S
- the type of the source. E.g. a ByteBuffer or a
Supplier
.D
- the type of the destination. E.g. a ByteBuffer or a
Consumer
.public abstract class OutboundHandler<S,D> extends ChannelHandler<OutboundHandler,S,D>
OutboundHandler
is a ChannelHandler
for outbound
traffic.
An example is the PacketEncoder that takes packets from the src (Provider) and
encodes them to the dst (ByteBuffer).
OutboundHandler
instances are not expected to be thread-safe;
each channel will gets its own instance(s).
A OutboundHandler
is constructed through a ChannelInitializer
.
onWrite()
is called, the first thing it should do is to call
IOUtil.compactOrClear(ByteBuffer)
so it flips to
writing mode. And at the end of the onWrite method, the destination buffer
should be flipped into reading mode.
If the OutboundHandler has a source buffer, it is expected to be
in reading mode and it is the responsibility of the OutboundHandler
in front to put that buffer in reading mode.Networking
,
InboundHandler
,
ChannelInitializer
,
ChannelErrorHandler
,
Channel
channel, dst, src
Constructor and Description |
---|
OutboundHandler() |
Modifier and Type | Method and Description |
---|---|
protected void |
initDstBuffer()
Initializes the dst ByteBuffer with the value for
ChannelOption.SO_SNDBUF . |
protected void |
initDstBuffer(int sizeBytes)
Initializes the dst ByteBuffer with the configured size.
|
protected void |
initDstBuffer(int sizeBytes,
byte[] bytes)
Initializes the dst ByteBuffer with the configured size.
|
abstract HandlerStatus |
onWrite()
A callback to indicate that this OutboundHandler should be
processed.
|
dst, dst, handlerAdded, interceptError, setChannel, src, src
public abstract HandlerStatus onWrite() throws Exception
HandlerStatus
the status of the handler after processing the src.Exception
- if something fails while executing the onWrite. When
an exception is thrown, the ChannelErrorHandler
is called.protected final void initDstBuffer()
ChannelOption.SO_SNDBUF
.
The buffer created is reading mode.protected final void initDstBuffer(int sizeBytes)
sizeBytes
- the size of the dst ByteBuffer.protected final void initDstBuffer(int sizeBytes, byte[] bytes)
sizeBytes
- the size of the dst ByteBuffer.bytes
- the bytes added to the buffer. Can be null if nothing
should be added.IllegalArgumentException
- if the size of the buffer is too small.Copyright © 2019 Hazelcast, Inc.. All Rights Reserved.