2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.remoting.transport.socket;
25
import org.jboss.logging.Logger;
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.io.OutputStream;
30
import java.net.Socket;
31
import java.net.SocketException;
34
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
36
public abstract class SocketWrapper
38
// Constants ------------------------------------------------------------------------------------
40
private static final Logger log = Logger.getLogger(SocketWrapper.class);
42
public static final String MARSHALLER = "marshaller";
43
public static final String UNMARSHALLER = "unmarshaller";
44
public static final String TEMP_TIMEOUT = "temptimeout";
45
public static final String WRITE_TIMEOUT = "writeTimeout";
47
protected static final int CLOSING = 254;
49
// Static ---------------------------------------------------------------------------------------
51
private static boolean trace = log.isTraceEnabled();
53
// Attributes -----------------------------------------------------------------------------------
55
protected Socket socket;
58
// Constructors ---------------------------------------------------------------------------------
60
protected SocketWrapper(Socket socket)
62
if (trace) { log.trace("constructing " + getClass().getName() + " instance for " + socket); }
66
protected SocketWrapper(Socket socket, Integer timeoutInt) throws SocketException
68
if (trace) { log.trace("constructing " + getClass().getName() + " instance for " + socket + ", using timeout " + timeoutInt); }
71
if(timeoutInt != null)
73
this.timeout = timeoutInt.intValue();
74
setTimeout(this.timeout);
78
// Public ---------------------------------------------------------------------------------------
80
public void setTimeout(int timeout) throws SocketException
82
if (trace) { log.trace(this + " setting timeout to " + timeout); }
83
this.timeout = timeout;
86
socket.setSoTimeout(timeout);
90
public int getTimeout()
95
public void close() throws IOException
99
log.trace(this + " closing socket");
101
log.trace(this + " closed socket");
105
public boolean isClosed()
110
return socket.isClosed();
113
public Socket getSocket()
118
public abstract OutputStream getOutputStream() throws IOException;
120
public abstract InputStream getInputStream() throws IOException;
122
public abstract void checkConnection() throws IOException;
124
// Package protected ----------------------------------------------------------------------------
126
// Protected ------------------------------------------------------------------------------------
128
protected void finalize()
138
log.debug(this + " failed to close socket", e);
143
// Private --------------------------------------------------------------------------------------
145
// Inner classes --------------------------------------------------------------------------------
b'\\ No newline at end of file'