public abstract class AbstractAsyncSocketTransport extends Object implements AsyncSocketTransport
ConnectionState
for all connections to the same host and port and issues only one retry for all connections.Modifier and Type | Field and Description |
---|---|
protected AsyncSocketTransportConfig |
config |
protected ConnectionStatus |
connectionStatus
ConnectionStatus of this connection.
|
protected String |
connectionString |
protected String |
host |
protected long |
lastConnectTime
Last time a successful connection was made.
|
protected long |
lastUseTime
Last time this connection was used.
|
protected int |
port |
protected int |
serverIndex |
protected AsyncSocketTransportFactory |
transportFactory |
Constructor and Description |
---|
AbstractAsyncSocketTransport(String phost,
int pport) |
Modifier and Type | Method and Description |
---|---|
void |
connect(AsyncHandler<Boolean> handler)
Connects to Socket and calls handler with true on success and false with
Exception on failure.
|
protected abstract void |
connectInternal(AsyncHandler<Boolean> handler)
Connect Method to be implemented by sub-class.
|
AsyncSocketTransportConfig |
getConfig()
Gets the AsyncSocketTransport config in use.
|
String |
getConnectionString()
Gets the Connection String in the form of host:port so that it does not have to be constructed
each time.
|
long |
getDownSince()
Returns the millisecond time since this connection was down.
|
String |
getHost()
Gets the host.
|
int |
getPort()
Gets the port.
|
long |
getRetryInterval()
The current retry interval as per the exponential fall back calculation.
|
int |
getServerIndex()
Gets an index identifying the server.
|
ConnectionStatus |
getStatus()
Returns the Connection Status
|
AsyncSocketTransportFactory |
getTransportFactory()
Returns the transportFactory for this connection.
|
boolean |
isStale()
Checks if the connection is stale as per configured idle timeout.
|
void |
setConfig(AsyncSocketTransportConfig pconfig)
Sets the AsyncSocketTransport config to use.
|
String |
toString()
Returns a String representation containing the host and port.
|
protected void |
updateConnectionStatus(ConnectionStatus status,
Throwable e)
Method to update the connection status.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, flush, read, requiresFlush, write
protected final String host
protected final int port
protected final String connectionString
protected int serverIndex
protected AsyncSocketTransportFactory transportFactory
protected AsyncSocketTransportConfig config
protected long lastUseTime
protected long lastConnectTime
protected volatile ConnectionStatus connectionStatus
public AbstractAsyncSocketTransport(String phost, int pport)
phost
- Server Hostpport
- Server Portprotected abstract void connectInternal(AsyncHandler<Boolean> handler)
handler
- handler to call when connection is completedprotected void updateConnectionStatus(ConnectionStatus status, Throwable e)
status
- New Connection Statuse
- Exception in case the Connection Status is DOWNpublic ConnectionStatus getStatus()
AsyncSocketTransport
getStatus
in interface AsyncSocketTransport
public void connect(AsyncHandler<Boolean> handler)
AsyncSocketTransport
connect
in interface AsyncSocketTransport
handler
- Handler to callpublic AsyncSocketTransportFactory getTransportFactory()
public long getDownSince()
AsyncSocketTransport
getDownSince
in interface AsyncSocketTransport
public long getRetryInterval()
AsyncSocketTransport
getRetryInterval
in interface AsyncSocketTransport
public AsyncSocketTransportConfig getConfig()
AsyncSocketTransport
getConfig
in interface AsyncSocketTransport
public void setConfig(AsyncSocketTransportConfig pconfig)
AsyncSocketTransport
setConfig
in interface AsyncSocketTransport
pconfig
- to usepublic boolean isStale()
AsyncSocketTransport
isStale
in interface AsyncSocketTransport
public String toString()
public String getHost()
ServerInfo
getHost
in interface ServerInfo
public int getPort()
ServerInfo
getPort
in interface ServerInfo
public String getConnectionString()
ServerInfo
getConnectionString
in interface ServerInfo
public int getServerIndex()
ServerInfo
getServerIndex
in interface ServerInfo
Copyright © 2013- Suresh Mahalingam. All Rights Reserved.