BrotliEncoder Class — netty Architecture
Architecture documentation for the BrotliEncoder class in BrotliEncoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD cbdb377e_e1ea_86a4_5944_9d2fa3e5025c["BrotliEncoder"] 7b4f39c5_54d8_a348_18fa_f3dc6dbd5432["BrotliEncoder.java"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|defined in| 7b4f39c5_54d8_a348_18fa_f3dc6dbd5432 5d60e662_924a_d3e6_af08_10dc60fdfe55["BrotliEncoder()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| 5d60e662_924a_d3e6_af08_10dc60fdfe55 6cbca021_11cb_c86c_c018_69f77efa84bf["handlerAdded()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| 6cbca021_11cb_c86c_c018_69f77efa84bf 07d81b36_e998_6233_a205_2d1dad528675["handlerRemoved()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| 07d81b36_e998_6233_a205_2d1dad528675 f1f60259_b8b8_2579_82be_39debafacd41["encode()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| f1f60259_b8b8_2579_82be_39debafacd41 aa67448e_54be_ac4a_4841_131ae7dc2553["ByteBuf()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| aa67448e_54be_ac4a_4841_131ae7dc2553 dd67ad33_5581_df40_ac45_db0b1422e0ee["isSharable()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| dd67ad33_5581_df40_ac45_db0b1422e0ee 5ae03be7_1763_8b14_3172_25c0da61193c["finish()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| 5ae03be7_1763_8b14_3172_25c0da61193c 4348774c_38a4_2a31_e98d_d0c02ec41984["ChannelFuture()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| 4348774c_38a4_2a31_e98d_d0c02ec41984 e044a0a0_3440_c839_e554_9efe949bbe03["close()"] cbdb377e_e1ea_86a4_5944_9d2fa3e5025c -->|method| e044a0a0_3440_c839_e554_9efe949bbe03
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/BrotliEncoder.java lines 42–279
@ChannelHandler.Sharable
public final class BrotliEncoder extends MessageToByteEncoder<ByteBuf> {
private static final AttributeKey<Writer> ATTR = AttributeKey.valueOf("BrotliEncoderWriter");
private final Encoder.Parameters parameters;
private final boolean isSharable;
private Writer writer;
/**
* Create a new {@link BrotliEncoder} Instance with {@link BrotliOptions#DEFAULT}
* and {@link #isSharable()} set to {@code true}
*/
public BrotliEncoder() {
this(BrotliOptions.DEFAULT);
}
/**
* Create a new {@link BrotliEncoder} Instance
*
* @param brotliOptions {@link BrotliOptions} to use and
* {@link #isSharable()} set to {@code true}
*/
public BrotliEncoder(BrotliOptions brotliOptions) {
this(brotliOptions.parameters());
}
/**
* Create a new {@link BrotliEncoder} Instance
* and {@link #isSharable()} set to {@code true}
*
* @param parameters {@link Encoder.Parameters} to use
*/
public BrotliEncoder(Encoder.Parameters parameters) {
this(parameters, true);
}
/**
* <p>
* Create a new {@link BrotliEncoder} Instance and specify
* whether this instance will be shared with multiple pipelines or not.
* </p>
*
* If {@link #isSharable()} is true then on {@link #handlerAdded(ChannelHandlerContext)} call,
* a new {@link Writer} will create, and it will be mapped using {@link Channel#attr(AttributeKey)}
* so {@link BrotliEncoder} can be shared with multiple pipelines. This works fine but there on every
* {@link #encode(ChannelHandlerContext, ByteBuf, ByteBuf)} call, we have to get the {@link Writer} associated
* with the appropriate channel. And this will add a overhead. So it is recommended to set {@link #isSharable()}
* to {@code false} and create new {@link BrotliEncoder} instance for every pipeline.
*
* @param parameters {@link Encoder.Parameters} to use
* @param isSharable Set to {@code true} if this instance is shared else set to {@code false}
*/
public BrotliEncoder(Encoder.Parameters parameters, boolean isSharable) {
super(ByteBuf.class);
this.parameters = ObjectUtil.checkNotNull(parameters, "Parameters");
this.isSharable = isSharable;
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
Writer writer = new Writer(parameters, ctx);
if (isSharable) {
ctx.channel().attr(ATTR).set(writer);
} else {
this.writer = writer;
}
super.handlerAdded(ctx);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
finish(ctx);
super.handlerRemoved(ctx);
}
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
// NO-OP
}
Source
Frequently Asked Questions
What is the BrotliEncoder class?
BrotliEncoder is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/BrotliEncoder.java.
Where is BrotliEncoder defined?
BrotliEncoder is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/BrotliEncoder.java at line 42.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free