public class TCPConnection extends Object implements Connection
TCPConnection is a wrapper around SocketChannel; it
represents a physical network connection with dsestination host (server). The
class keeps the supplied ConnectionConfig which is used to reconnect.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
isConnected |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
closing a physical connection to the remote machine.
|
boolean |
connect()
Establishes a physical connection with destination server.
|
ConnectionConfig |
getConnConfig() |
String |
getId()
Every connection has an unique id assigned.
|
long |
getLastActivity()
A byte read/write, connect and disconnect are marked as activity on
Connection. |
boolean |
isConnected()
Check if this connection is connected.
|
int |
read(ByteBuffer buffer)
Reads incoming data from this connection into the destination buffer
|
int |
write(ByteBuffer buffer)
Drains buffer bytes on the underlying connection
|
void |
write(Writable writable)
Write
Writables onto this connection. |
public boolean connect()
throws IOException
connect in interface ConnectionIOException - IOExceptionpublic int read(ByteBuffer buffer) throws IOException
Connectionread in interface Connectionbuffer - bufferIOException - IOExceptionpublic void write(Writable writable) throws IOException
ConnectionWritables onto this connection. It is recommended that this
method be used to write packet onto a connection. A failure in write will
result in socket close.write in interface Connectionwritable - writableIOException - IOExceptionpublic int write(ByteBuffer buffer) throws IOException
Connectionwrite in interface Connectionbuffer - byte buffer which will drained on underlying socketIOException - if IO error occures while writing datapublic ConnectionConfig getConnConfig()
public String getId()
ConnectionConnectiongetId in interface Identifiable<String>getId in interface Connectionpublic boolean isConnected()
ConnectionThe method used to determine connection state in multi-threaded environment; therefore it is advised that implementation of this method is synchronized on the connection object.
isConnected in interface Connectionpublic long getLastActivity()
ConnectionConnection. The method returns time of last activity on this
conenction.getLastActivity in interface Connectionpublic void close()
throws IOException
Connectionclose in interface Connectionclose in interface AutoCloseableIOException - IOExceptionCopyright © 2019. All rights reserved.