Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.go.trove.net
Class LazySocketFactory  view LazySocketFactory download LazySocketFactory.java

java.lang.Object
  extended bycom.go.trove.net.LazySocketFactory
All Implemented Interfaces:
SocketFactory

public class LazySocketFactory
extends java.lang.Object
implements SocketFactory

A socket implementation that lazily establishs a connection. It only connects when actually needed. Setting options and getting I/O streams will not force a connection to be established. As soon as a read or write operation is performed, a connection is established.

If the first write operation requires a connection to be established, then a recycled connection is requested. The connection is tested by writing the data to it. If this fails, a new connection is requested and the operation is tried again.

Version:
4 , 00/12/05

Field Summary
private  SocketFactory mFactory
           
 
Constructor Summary
LazySocketFactory(SocketFactory factory)
           
 
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 socket that will lazily connect.
 CheckedSocket getSocket(long timeout)
          Returns a socket that will lazily connect.
 CheckedSocket getSocket(java.lang.Object session)
          Returns a socket that will lazily connect.
 CheckedSocket getSocket(java.lang.Object session, long timeout)
          Returns a socket that will lazily connect.
 void recycleSocket(CheckedSocket cs)
          Recycle a socket connection that was returned from the getSocket or createSocket methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mFactory

private final SocketFactory mFactory
Constructor Detail

LazySocketFactory

public LazySocketFactory(SocketFactory factory)
Method Detail

getInetAddressAndPort

public InetAddressAndPort getInetAddressAndPort()
Description copied from interface: SocketFactory
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.

Specified by:
getInetAddressAndPort in interface SocketFactory

getInetAddressAndPort

public InetAddressAndPort getInetAddressAndPort(java.lang.Object session)
Description copied from interface: SocketFactory
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.

Specified by:
getInetAddressAndPort in interface SocketFactory

getDefaultTimeout

public long getDefaultTimeout()
Description copied from interface: SocketFactory
Returns the default timeout for creating or getting sockets or -1 if infinite.

Specified by:
getDefaultTimeout in interface SocketFactory

createSocket

public CheckedSocket createSocket()
                           throws java.net.ConnectException,
                                  java.net.SocketException
Description copied from interface: SocketFactory
Must always return a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.

Specified by:
createSocket in interface SocketFactory

createSocket

public CheckedSocket createSocket(java.lang.Object session)
                           throws java.net.ConnectException,
                                  java.net.SocketException
Description copied from interface: SocketFactory
Returns a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.

Specified by:
createSocket in interface SocketFactory

createSocket

public CheckedSocket createSocket(long timeout)
                           throws java.net.ConnectException,
                                  java.net.SocketException
Description copied from interface: SocketFactory
Returns a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.

Specified by:
createSocket in interface SocketFactory

createSocket

public CheckedSocket createSocket(java.lang.Object session,
                                  long timeout)
                           throws java.net.ConnectException,
                                  java.net.SocketException
Description copied from interface: SocketFactory
Returns a new socket connection. When the socket is no longer needed, call recycleSocket so that it be used again.

Specified by:
createSocket in interface SocketFactory

getSocket

public CheckedSocket getSocket()
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a socket that will lazily connect.

Specified by:
getSocket in interface SocketFactory

getSocket

public CheckedSocket getSocket(java.lang.Object session)
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a socket that will lazily connect.

Specified by:
getSocket in interface SocketFactory

getSocket

public CheckedSocket getSocket(long timeout)
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a socket that will lazily connect.

Specified by:
getSocket in interface SocketFactory

getSocket

public CheckedSocket getSocket(java.lang.Object session,
                               long timeout)
                        throws java.net.ConnectException,
                               java.net.SocketException
Returns a socket that will lazily connect.

Specified by:
getSocket in interface SocketFactory

recycleSocket

public void recycleSocket(CheckedSocket cs)
                   throws java.net.SocketException,
                          java.lang.IllegalArgumentException
Description copied from interface: SocketFactory
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.

Specified by:
recycleSocket in interface SocketFactory

clear

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

Specified by:
clear in interface SocketFactory

getAvailableCount

public int getAvailableCount()
Description copied from interface: SocketFactory
Returns the number of recycled sockets currently available.

Specified by:
getAvailableCount in interface SocketFactory