Interface SocketCommListener
- Author:
- Christopher Mindus
Method Summary
Modifier and TypeMethodDescriptionvoidonCommClosed(SocketCommNIO comm) Called when the communication link is closed.voidonCommConnected(SocketCommNIO comm) Called when the communication link is connected.voidonCommData(SocketCommNIO comm, ByteBuffer buf) Called when the communication link has received data.voidonCommError(SocketCommNIO comm, IOException e) Called when the communication link is closed.voidonCommOpen(SocketCommNIO comm) Called when the communication link is opened.voidonCommState(SocketCommNIO comm) Called when the state changes.voidonCommTimeout(SocketCommNIO comm, boolean isReadTimeout) Called when the communication link has timed out on a read or write operation.
Method Details
onCommOpen
Called when the communication link is opened.- Parameters:
comm- The socket communication instance.
onCommState
Called when the state changes.onCommConnected
Called when the communication link is connected.- Parameters:
comm- The socket communication instance.
onCommData
Called when the communication link has received data.The listener must consume or copy the entire contents of
bufbefore returning. The buffer is owned by the communication layer and is invalid once this method returns: it is cleared and reused for the next read, and in plain (non-secure) mode it is a single direct buffer shared by every socket served by the sameWorkerNIO, so its contents may be replaced by data belonging to another connection.The buffer is equally invalid once the listener calls back into
comm.close()orcomm.send(): a re-entrant path can reach the read loop again and refill the buffer before the call returns. Consume or copy the data before making any such call.That rule is enforced rather than merely documented. Once
SocketCommNIO.getState()reportsCLOSING, the communication layer stops dispatching to this method altogether, on the plain and the secure path alike. Suppression begins atCLOSING, not atCLOSED, so it takes effect when a close is requested rather than when it completes. Reading continues in that state, so the peer'sclose_notifystill arrives and end-of-stream is still detected; only the dispatch is suppressed. A listener that closes from inside this method therefore receives no further callback, where previously it could still be handed data that the peer had sent before the close completed.A listener that requires more data than
bufcurrently holds, e.g. a protocol record split across TCP segments or TLS records, must copy the bytes into its own accumulator and retain its parse state across calls. It must never retain a reference tobuf.- Parameters:
comm- The socket communication instance.buf- The received data. Must be fully consumed or copied before returning.
onCommTimeout
Called when the communication link has timed out on a read or write operation.- Parameters:
comm- The socket communication instance.isReadTimeout- Flag indicating read timeout when true, false indicates write timeout.
onCommError
Called when the communication link is closed.- Parameters:
comm- The socket communication instance.e- The exception.
onCommClosed
Called when the communication link is closed.- Parameters:
comm- The socket communication instance.