com.continuent.tungsten.common.sockets
Class ServerSocketService

java.lang.Object
  extended by com.continuent.tungsten.common.sockets.ServerSocketService

public class ServerSocketService
extends java.lang.Object

Provides a wrapper for managing server-side Socket connections. This class encapsulates SSL vs. non-SSL operation, and closing the connection. The code assumes properties required for SSL operation have been previously set before SSL sockets are allocated.

Author:
Robert Hodges

Constructor Summary
ServerSocketService()
          Creates a new wrapper for client connections.
 
Method Summary
 SocketWrapper accept()
          Accepts a connection the server socket.
 java.net.ServerSocket bind()
          Connect to the server socket.
 void close()
          Close server socket.
 java.net.InetSocketAddress getAddress()
           
 int getLocalPort()
           
 java.net.ServerSocket getServerSocket()
          Returns the server socket.
 boolean isUseSSL()
           
 void setAcceptTimeout(int acceptTimeout)
          Time in milliseconds before timeout to check for termination when accepting connections.
 void setAddress(java.net.InetSocketAddress address)
          Sets the address to which we should connect.
 void setUseSSL(boolean useSSL)
          If set to true, use an SSL socket, otherwise use plain TCP/IP.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerSocketService

public ServerSocketService()
Creates a new wrapper for client connections.

Method Detail

getAddress

public java.net.InetSocketAddress getAddress()

setAddress

public void setAddress(java.net.InetSocketAddress address)
Sets the address to which we should connect.


isUseSSL

public boolean isUseSSL()

setUseSSL

public void setUseSSL(boolean useSSL)
If set to true, use an SSL socket, otherwise use plain TCP/IP.


getLocalPort

public int getLocalPort()

setAcceptTimeout

public void setAcceptTimeout(int acceptTimeout)
Time in milliseconds before timeout to check for termination when accepting connections. When using SSL this must be set to a low value as SSL sockets are not interruptible during this operation.


bind

public java.net.ServerSocket bind()
                           throws java.io.IOException
Connect to the server socket.

Throws:
java.io.IOException

accept

public SocketWrapper accept()
                     throws java.io.IOException
Accepts a connection the server socket.

Returns:
A socket wrapper
Throws:
SocketTerminationException - Thrown if the server socket has been terminated by a call to close()
java.io.IOException - Thrown if a generic exception occurs during I/O

getServerSocket

public java.net.ServerSocket getServerSocket()
Returns the server socket.


close

public void close()
Close server socket. Client must call this from a separate thread to break hangs on bind() and accept() calls. This is synchronized to prevent accidental double calls.