@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, writebind, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaughtclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaughtpublic BrotliEncoder()
public BrotliEncoder(BrotliOptions brotliOptions)
BrotliEncoder InstancebrotliOptions - BrotliOptions to use and
isSharable() set to truepublic 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 falsepublic void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapterhandlerAdded 在接口中 ChannelHandlerhandlerAdded 在类中 ChannelHandlerAdapterjava.lang.Exceptionpublic void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapterhandlerRemoved 在接口中 ChannelHandlerhandlerRemoved 在类中 ChannelHandlerAdapterjava.lang.Exceptionprotected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws java.lang.Exception
MessageToByteEncoderByteBuf. 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
MessageToByteEncoderByteBuf 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.Exceptionpublic boolean isSharable()
ChannelHandlerAdapterisSharable 在类中 ChannelHandlerAdapterpublic 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
ChannelOutboundHandlerAdapterChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.close 在接口中 ChannelOutboundHandlerclose 在类中 ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurs