edu.emory.mathcs.util.net
Class ServerSocketWrapper

java.lang.Object
  extended byjava.net.ServerSocket
      extended byedu.emory.mathcs.util.net.ServerSocketWrapper
Direct Known Subclasses:
CompressedServerSocketWrapper

public abstract class ServerSocketWrapper
extends java.net.ServerSocket

Wrapper for server sockets which enables to add functionality in subclasses on top of existing, bound server sockets. It is useful when direct subclassing of delegate socket class is not possible, e.g. if the delegate socket is created by a library. Possible usage example is socket factory chaining. This class delegates all socket-related requests to the wrapped delegate, as of JDK 1.4.

Version:
1.4
Author:
Dawid Kurzyniec

Field Summary
protected  java.net.ServerSocket delegate
          the wrapped delegate socket.
 
Constructor Summary
protected ServerSocketWrapper(java.net.ServerSocket delegate)
          Creates new socket wrapper for a given server socket.
 
Method Summary
 java.net.Socket accept()
           
 void close()
           
 boolean equals(java.lang.Object obj)
           
 java.nio.channels.ServerSocketChannel getChannel()
           
 java.net.InetAddress getInetAddress()
           
 int getLocalPort()
           
 java.net.SocketAddress getLocalSocketAddress()
           
 int getReceiveBufferSize()
           
 boolean getReuseAddress()
           
 int getSoTimeout()
           
 int hashCode()
           
 boolean isBound()
          Returns true, indicating that the socket is bound.
 boolean isClosed()
           
 void setReceiveBufferSize(int size)
           
 void setReuseAddress(boolean on)
           
 void setSoTimeout(int timeout)
           
 java.lang.String toString()
           
protected abstract  java.net.Socket wrapAcceptedSocket(java.net.Socket socket)
           
 
Methods inherited from class java.net.ServerSocket
bind, bind, implAccept, setSocketFactory
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

delegate

protected final java.net.ServerSocket delegate
the wrapped delegate socket.

Constructor Detail

ServerSocketWrapper

protected ServerSocketWrapper(java.net.ServerSocket delegate)
                       throws java.io.IOException
Creates new socket wrapper for a given server socket. The delegate must be bound and it must not be closed.

Parameters:
delegate - the delegate socket to wrap
Throws:
java.net.SocketException - if the delegate socket is closed, not bound, or not connected
java.io.IOException
Method Detail

isBound

public boolean isBound()
Returns true, indicating that the socket is bound.

Returns:
true

isClosed

public boolean isClosed()

getInetAddress

public java.net.InetAddress getInetAddress()

getLocalPort

public int getLocalPort()

getLocalSocketAddress

public java.net.SocketAddress getLocalSocketAddress()

accept

public java.net.Socket accept()
                       throws java.io.IOException
Throws:
java.io.IOException

wrapAcceptedSocket

protected abstract java.net.Socket wrapAcceptedSocket(java.net.Socket socket)
                                               throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getChannel

public java.nio.channels.ServerSocketChannel getChannel()

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Throws:
java.net.SocketException

getSoTimeout

public int getSoTimeout()
                 throws java.io.IOException
Throws:
java.io.IOException

setReuseAddress

public void setReuseAddress(boolean on)
                     throws java.net.SocketException
Throws:
java.net.SocketException

getReuseAddress

public boolean getReuseAddress()
                        throws java.net.SocketException
Throws:
java.net.SocketException

toString

public java.lang.String toString()

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws java.net.SocketException
Throws:
java.net.SocketException

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
Throws:
java.net.SocketException

equals

public boolean equals(java.lang.Object obj)

hashCode

public int hashCode()