|
|||||||||
| Home >> All >> com >> go >> trove >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.go.trove.net
Class DistributedSocketFactory

java.lang.Objectcom.go.trove.net.DistributedSocketFactory
- All Implemented Interfaces:
- SocketFactory
- Direct Known Subclasses:
- MultiPooledSocketFactory
- public class DistributedSocketFactory
- extends java.lang.Object
- implements SocketFactory
- extends java.lang.Object
A SocketFactory implementation for distributing load among several SocketFactories. If an exception occurs on a socket, its pool is put into the "dead" list. A special thread will run in the background, trying to resurrect the dead SocketSocket. As soon as its able to create sockets again, its added back into the "live" list.
Consider wrapping with a LazySocketFactory for automatic checking against socket factories that may be dead.
- Version:
- 7 , 01/01/22
| Nested Class Summary | |
private static class |
DistributedSocketFactory.Resurrector
|
| Field Summary | |
private java.util.List |
mFactories
|
private int |
mFactoryIndex
|
private CheckedSocket.ExceptionListener |
mListener
|
private java.util.Map |
mResurrectors
|
private java.util.Map |
mSocketSources
|
private long |
mTimeout
|
| Constructor Summary | |
DistributedSocketFactory(long timeout)
|
|
| Method Summary | |
void |
addSocketFactory(SocketFactory factory)
|
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. |
private void |
deadFactory(SocketFactory factory)
|
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. |
private SocketFactory |
getFactory(int index)
The provided index must be positive, but it can be out of the factory list bounds. |
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. |
void |
removeSocketFactory(SocketFactory factory)
|
private int |
selectFactory(java.lang.Object session)
Returns an index which is positive, but may be out of the factory list bounds. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
mTimeout
private final long mTimeout
mFactoryIndex
private int mFactoryIndex
mFactories
private java.util.List mFactories
mResurrectors
private java.util.Map mResurrectors
mSocketSources
private java.util.Map mSocketSources
mListener
private CheckedSocket.ExceptionListener mListener
| Constructor Detail |
DistributedSocketFactory
public DistributedSocketFactory(long timeout)
| Method Detail |
addSocketFactory
public void addSocketFactory(SocketFactory factory)
removeSocketFactory
public void removeSocketFactory(SocketFactory factory)
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:
getInetAddressAndPortin interfaceSocketFactory
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:
getInetAddressAndPortin interfaceSocketFactory
getDefaultTimeout
public long getDefaultTimeout()
- Description copied from interface:
SocketFactory - Returns the default timeout for creating or getting sockets or -1 if
infinite.
- Specified by:
getDefaultTimeoutin interfaceSocketFactory
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
recycleSocketso that it be used again.- Specified by:
createSocketin interfaceSocketFactory
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
recycleSocketso that it be used again.- Specified by:
createSocketin interfaceSocketFactory
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
recycleSocketso that it be used again.- Specified by:
createSocketin interfaceSocketFactory
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
recycleSocketso that it be used again.- Specified by:
createSocketin interfaceSocketFactory
getSocket
public CheckedSocket getSocket() throws java.net.ConnectException, java.net.SocketException
- Description copied from interface:
SocketFactory - Returns a new or recycled socket connection. When the socket is no
longer needed, call
recycleSocketso that it be used again.- Specified by:
getSocketin interfaceSocketFactory
getSocket
public CheckedSocket getSocket(java.lang.Object session) throws java.net.ConnectException, java.net.SocketException
- Description copied from interface:
SocketFactory - Returns a new or recycled socket connection. When the socket is no
longer needed, call
recycleSocketso that it be used again.- Specified by:
getSocketin interfaceSocketFactory
getSocket
public CheckedSocket getSocket(long timeout) throws java.net.ConnectException, java.net.SocketException
- Description copied from interface:
SocketFactory - Returns a new or recycled socket connection. When the socket is no
longer needed, call
recycleSocketso that it be used again.- Specified by:
getSocketin interfaceSocketFactory
getSocket
public CheckedSocket getSocket(java.lang.Object session, long timeout) throws java.net.ConnectException, java.net.SocketException
- Description copied from interface:
SocketFactory - Returns a new or recycled socket connection. When the socket is no
longer needed, call
recycleSocketso that it be used again.- Specified by:
getSocketin interfaceSocketFactory
recycleSocket
public void recycleSocket(CheckedSocket socket) throws java.net.SocketException, java.lang.IllegalArgumentException
- Description copied from interface:
SocketFactory - Recycle a socket connection that was returned from the
getSocketorcreateSocketmethods. 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:
recycleSocketin interfaceSocketFactory
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:
clearin interfaceSocketFactory
getAvailableCount
public int getAvailableCount()
- Description copied from interface:
SocketFactory - Returns the number of recycled sockets currently available.
- Specified by:
getAvailableCountin interfaceSocketFactory
getFactory
private SocketFactory getFactory(int index) throws java.net.ConnectException
- The provided index must be positive, but it can be out of the factory
list bounds.
selectFactory
private int selectFactory(java.lang.Object session) throws java.net.ConnectException
- Returns an index which is positive, but may be out of the factory list
bounds.
deadFactory
private void deadFactory(SocketFactory factory)
|
|||||||||
| Home >> All >> com >> go >> trove >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.go.trove.net.DistributedSocketFactory