public interface Connection extends AutoCloseable, Identifiable<String>
| 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.
|
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. |
String getId()
ConnectiongetId in interface Identifiable<String>boolean connect()
throws IOException
IOException - IOExceptionboolean isConnected()
The 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.
int read(ByteBuffer buffer) throws IOException
buffer - bufferIOException - IOExceptionint write(ByteBuffer buffer) throws IOException
buffer - byte buffer which will drained on underlying socketIOException - if IO error occures while writing datavoid write(Writable writable) throws IOException
Writables 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.writable - writableIOException - IOExceptionlong getLastActivity()
Connection. The method returns time of last activity on this
conenction.void close()
throws IOException
close in interface AutoCloseableIOException - IOExceptionCopyright © 2019. All rights reserved.