com.go.trove.net
Interface SocketFactory

All Known Implementing Classes:
DistributedSocketFactory, LazySocketFactory, PlainSocketFactory, PooledSocketFactory

public interface SocketFactory

Allows client sockets to be created or recycled.

Version:
3 , 00/12/05
Author:
Brian S O'Neill

Method Summary
 void clear()
          Closes all recycled connections, but does not prevent new connections from being created and recycled.
 CheckedSocket createSocket()
          Must always return a new socket connection.
 CheckedSocket createSocket(long timeout)
          Returns a new socket connection.
 CheckedSocket createSocket(java.lang.Object session)
          Returns a new socket connection.
 CheckedSocket createSocket(java.lang.Object session, long timeout)
          Returns a new socket connection.
 int getAvailableCount()
          Returns the number of recycled sockets currently available.
 long getDefaultTimeout()
          Returns the default timeout for creating or getting sockets or -1 if infinite.
 InetAddressAndPort getInetAddressAndPort()
          Returns the InetAddress and port that this factory will most likely connect to.
 InetAddressAndPort getInetAddressAndPort(java.lang.Object session)
          Returns the InetAddress and port that this factory will most likely connect to.
 CheckedSocket getSocket()
          Returns a new or recycled socket connection.
 CheckedSocket getSocket(long timeout)
          Returns a new or recycled socket connection.
 CheckedSocket getSocket(java.lang.Object session)
          Returns a new or recycled socket connection.
 CheckedSocket getSocket(java.lang.Object session, long timeout)
          Returns a new or recycled socket connection.
 void recycleSocket(CheckedSocket socket)
          Recycle a socket connection that was returned from the getSocket or createSocket methods.
 

Method Detail

getInetAddressAndPort

public InetAddressAndPort getInetAddressAndPort()
Returns the InetAddress and port that this factory will most likely connect to. If the address isn't precisely known, its value is 0.0.0.0. If the port isn't known, its value is -1.

getInetAddressAndPort

public InetAddressAndPort getInetAddressAndPort(java.lang.Object session)
Returns the InetAddress and port that this factory will most likely connect to. If the address isn't precisely known, its value is 0.0.0.0. If the port isn't known, its value is -1.
Parameters:
session - Object whose hashcode might be used to select a specific connection if factory is distributed. If null, then no session is used.

getDefaultTimeout

public long getDefaultTimeout()
Returns the default timeout for creating or getting sockets or -1 if infinite.

createSocket

public CheckedSocket createSocket()
                           throws java.net.ConnectException,
                                  java.net.SocketException
Must always return a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

createSocket

public CheckedSocket createSocket(java.lang.Object session)
                           throws java.net.ConnectException,
                                  java.net.SocketException
Returns a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Parameters:
session - Object whose hashcode might be used to select a specific connection if factory is distributed. If null, then no session is used.
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

createSocket

public CheckedSocket createSocket(long timeout)
                           throws java.net.ConnectException,
                                  java.net.SocketException
Returns a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Parameters:
timeout - Maximum time to wait (in milliseconds) for a connection to be created before throwing a ConnectException
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

createSocket

public CheckedSocket createSocket(java.lang.Object session,
                                  long timeout)
                           throws java.net.ConnectException,
                                  java.net.SocketException
Returns a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Parameters:
session - Object whose hashcode might be used to select a specific connection if factory is distributed. If null, then no session is used.
timeout - Maximum time to wait (in milliseconds) for a connection to become available before throwing an exception
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

getSocket

public CheckedSocket getSocket()
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a new or recycled socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

getSocket

public CheckedSocket getSocket(java.lang.Object session)
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a new or recycled socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Parameters:
session - Object whose hashcode might be used to select a specific connection if factory is distributed. If null, then no session is used.
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

getSocket

public CheckedSocket getSocket(long timeout)
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a new or recycled socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Parameters:
timeout - Maximum time to wait (in milliseconds) for a connection to be returned before throwing a ConnectException
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

getSocket

public CheckedSocket getSocket(java.lang.Object session,
                               long timeout)
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a new or recycled socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.
Parameters:
session - Object whose hashcode might be used to select a specific connection if factory is distributed. If null, then no session is used.
timeout - Maximum time to wait (in milliseconds) for a connection to be returned before throwing a ConnectException
Throws:
java.net.ConnectException - if timeout has elapsed and no socket is available or factory is closed

recycleSocket

public void recycleSocket(CheckedSocket socket)
                   throws java.net.SocketException,
                          java.lang.IllegalArgumentException
Recycle a socket connection that was returned from the getSocket or createSocket methods. Since SocketFactory has no knowledge of any protocol being used on the socket, it is the responsibility of the caller to ensure the socket is in a "clean" state. Depending on implementation, the recycled socket may simply be closed.
Parameters:
socket - Socket which must have come from this factory. Passing in null is ignored.

clear

public void clear()
Closes all recycled connections, but does not prevent new connections from being created and recycled.

getAvailableCount

public int getAvailableCount()
Returns the number of recycled sockets currently available.