@ChannelHandler.Sharable public final class BrotliEncoder extends MessageToByteEncoder<ByteBuf>
ChannelHandler.Sharable
Constructor and Description |
---|
BrotliEncoder()
|
BrotliEncoder(BrotliOptions brotliOptions)
Create a new
BrotliEncoder Instance |
BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
|
BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters,
boolean isSharable)
Create a new
BrotliEncoder Instance and specify
whether this instance will be shared with multiple pipelines or not. |
Modifier and Type | Method and Description |
---|---|
protected ByteBuf |
allocateBuffer(ChannelHandlerContext ctx,
ByteBuf msg,
boolean preferDirect)
Allocate a
ByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf) . |
void |
close(ChannelHandlerContext ctx,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline . |
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf msg,
ByteBuf out)
Encode a message into a
ByteBuf . |
void |
finish(ChannelHandlerContext ctx)
Finish the encoding, close streams and write final
ByteBuf to the channel. |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
boolean |
isSharable()
|
acceptOutboundMessage, isPreferDirect, write
bind, connect, deregister, disconnect, flush, read
ensureNotSharable, exceptionCaught
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionCaught
public BrotliEncoder()
public BrotliEncoder(BrotliOptions brotliOptions)
BrotliEncoder
InstancebrotliOptions
- BrotliOptions
to use and
isSharable()
set to true
public BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters)
parameters
- Encoder.Parameters
to usepublic BrotliEncoder(com.aayushatharva.brotli4j.encoder.Encoder.Parameters parameters, boolean isSharable)
Create a new BrotliEncoder
Instance and specify
whether this instance will be shared with multiple pipelines or not.
isSharable()
is true then on handlerAdded(ChannelHandlerContext)
call,
a new Writer
will create, and it will be mapped using AttributeMap.attr(AttributeKey)
so BrotliEncoder
can be shared with multiple pipelines. This works fine but there on every
encode(ChannelHandlerContext, ByteBuf, ByteBuf)
call, we have to get the Writer
associated
with the appropriate channel. And this will add a overhead. So it is recommended to set isSharable()
to false
and create new BrotliEncoder
instance for every pipeline.parameters
- Encoder.Parameters
to useisSharable
- Set to true
if this instance is shared else set to false
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerAdded
in interface ChannelHandler
handlerAdded
in class ChannelHandlerAdapter
Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
handlerRemoved
in interface ChannelHandler
handlerRemoved
in class ChannelHandlerAdapter
Exception
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception
MessageToByteEncoder
ByteBuf
. This method will be called for each written message that can be handled
by this encoder.encode
in class MessageToByteEncoder<ByteBuf>
ctx
- the ChannelHandlerContext
which this MessageToByteEncoder
belongs tomsg
- the message to encodeout
- the ByteBuf
into which the encoded message will be writtenException
- is thrown if an error occursprotected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception
MessageToByteEncoder
ByteBuf
which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf)
.
Sub-classes may override this method to return ByteBuf
with a perfect matching initialCapacity
.allocateBuffer
in class MessageToByteEncoder<ByteBuf>
Exception
public boolean isSharable()
ChannelHandlerAdapter
isSharable
in class ChannelHandlerAdapter
public void finish(ChannelHandlerContext ctx) throws IOException
ByteBuf
to the channel.ctx
- ChannelHandlerContext
which we want to closeIOException
- If an error occurred during closurepublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelOutboundHandlerAdapter
ChannelOutboundInvoker.close(ChannelPromise)
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.close
in interface ChannelOutboundHandler
close
in class ChannelOutboundHandlerAdapter
ctx
- the ChannelHandlerContext
for which the close operation is madepromise
- the ChannelPromise
to notify once the operation completesException
- thrown if an error occursCopyright © 2008–2024 The Netty Project. All rights reserved.