public interface Connection extends Closeable
Modifier and Type | Interface and Description |
---|---|
static class |
Connection.OperationType
An enumeration of the managed operations manipulable by the user.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this connection.
|
Throwable |
getException()
Gets the exception that occurred.
|
Object |
getLock()
Gets the monitor for enforcing mutual exclusion over operations on this connection.
|
<V> Future<V> |
invoke(Callable<V> c)
Executes the given code snippet on this connection's
ConnectionManager thread. |
boolean |
isManagerThread()
Gets whether this connection's
ConnectionManager thread is the current thread. |
int |
send(ByteBuffer bb)
Sends data to the remote host.
|
void |
setEnabled(Connection.OperationType type,
boolean enabled)
Enables/disables various managed operations:
Connection.OperationType.READ -- The ConnectionHandler.onReceive(ByteBuffer) callback is
enabled/disabled. |
void |
setException(Throwable exception)
Sets the exception and triggers connection closure.
|
String |
toString()
Creates a human-readable representation of this connection.
|
int send(ByteBuffer bb)
bb
- the ByteBuffer
containing data. It must be in ready-to-read mode.byte
s remaining in this connection's write buffer; is greater than 0
if and
only if not all byte
s could be written out to the network, and have to be stored locally for the
time being.void setEnabled(Connection.OperationType type, boolean enabled)
Connection.OperationType.READ
-- The ConnectionHandler.onReceive(ByteBuffer)
callback is
enabled/disabled. With argument true
, this method shall guarantee that
ConnectionHandler.onReceive(ByteBuffer)
will subsequently be called at least once.Connection.OperationType.WRITE
-- Managed writes of data buffered by the send(ByteBuffer)
method are
enabled/disabled.type
- the Connection.OperationType
.enabled
- whether the given operation is enabled or disabled.Connection.OperationType
Throwable getException()
void setException(Throwable exception)
exception
- the exception.ConnectionHandler.ClosingType.ERROR
Object getLock()
boolean isManagerThread()
ConnectionManager
thread is the current thread.true
if and only if this connection's ConnectionManager
thread is the current thread.
Note: All code where this test returns true
are thread-safe with respect to callbacks.Thread.currentThread()
<V> Future<V> invoke(Callable<V> c)
ConnectionManager
thread.void close()
close
in interface AutoCloseable
close
in interface Closeable