public interface ReadHandler
ByteBuffer
and processes it. The ReadHandler is invoked by the SocketReader
after
it has read data from the socket.
A typical example is that Packet instances are created from the buffered data and handing them over the the
PacketDispatcher
. See MemberReadHandler
for more information.
Each SocketReader
will have its own ReadHandler
instance. Therefor it doesn't need to be thread-safe.
MemberReadHandler
that reads out any Packet from the decrypted ByteBuffer. Using this approach encryption can easily be added to any type of
communication, not only member 2 member communication.
Currently security is added by using a SocketChannelWrapper
, but this is not needed if the handlers form a pipeline.
Netty follows a similar approach with pipelining and adding encryption.
There is no explicit support for setting up a 'pipeline' of ReadHandler/WriterHandlers but t can easily be realized by setting
up the chain and let a handler explicitly forward to the next. Since it isn't a common practice for the handler so far, isn't
needed to add additional complexity to the system; just set up a chain manually.
pseudo code:
public class DecryptingReadHandler implements ReadHandler { private final ReadHandler next; public DecryptingReadHandler(ReadHandler next) { this.next = next; } public void read(ByteBuffer src) { decrypt(src, decryptedSrc); next.read(decryptedSrc) } }The
next
ReadHandler is the next item in the pipeline.
For encryption is similar approach can be followed where the DecryptingWriteHandler is the last WriteHandler in the pipeline.WriteHandler
,
SocketReader
,
TcpIpConnection
,
IOThreadingModel
Modifier and Type | Method and Description |
---|---|
void |
onRead(ByteBuffer src)
A callback to indicate that data is available in the ByteBuffer to be processed.
|
void onRead(ByteBuffer src) throws Exception
src
- the ByteBuffer containing the data to read. The ByteBuffer is already in reading mode and when completed,
should not be converted to write-mode using clear/compact. That is a task of the SocketReader
.Exception
- if something fails while reading data from the ByteBuffer or processing the data
(e.g. when a Packet fails to get processed). When an exception is thrown, the TcpIpConnection
is closed. There is no point continuing with a potentially corrupted stream.Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.