@ChannelHandler.Sharable public final class BrotliEncoder extends MessageToByteEncoder<ByteBuf>
ChannelHandler.Sharable
构造器和说明 |
---|
BrotliEncoder()
|
BrotliEncoder(BrotliOptions brotliOptions)
Create a new
BrotliEncoder Instance |
BrotliEncoder(Encoder.Parameters parameters)
|
BrotliEncoder(Encoder.Parameters parameters,
boolean isSharable)
Create a new
BrotliEncoder Instance and specify
whether this instance will be shared with multiple pipelines or not. |
限定符和类型 | 方法和说明 |
---|---|
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(Encoder.Parameters parameters)
parameters
- Encoder.Parameters
to usepublic BrotliEncoder(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 java.lang.Exception
ChannelHandlerAdapter
handlerAdded
在接口中 ChannelHandler
handlerAdded
在类中 ChannelHandlerAdapter
java.lang.Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved
在接口中 ChannelHandler
handlerRemoved
在类中 ChannelHandlerAdapter
java.lang.Exception
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws java.lang.Exception
MessageToByteEncoder
ByteBuf
. This method will be called for each written message that can be handled
by this encoder.encode
在类中 MessageToByteEncoder<ByteBuf>
ctx
- the ChannelHandlerContext
which this MessageToByteEncoder
belongs tomsg
- the message to encodeout
- the ByteBuf
into which the encoded message will be writtenjava.lang.Exception
- is thrown if an error occursprotected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws java.lang.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
在类中 MessageToByteEncoder<ByteBuf>
java.lang.Exception
public boolean isSharable()
ChannelHandlerAdapter
isSharable
在类中 ChannelHandlerAdapter
public void finish(ChannelHandlerContext ctx) throws java.io.IOException
ByteBuf
to the channel.ctx
- ChannelHandlerContext
which we want to closejava.io.IOException
- If an error occurred during closurepublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerAdapter
ChannelOutboundInvoker.close(ChannelPromise)
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.close
在接口中 ChannelOutboundHandler
close
在类中 ChannelOutboundHandlerAdapter
ctx
- the ChannelHandlerContext
for which the close operation is madepromise
- the ChannelPromise
to notify once the operation completesjava.lang.Exception
- thrown if an error occurs