HexDumpProxyFrontendHandler Class — netty Architecture
Architecture documentation for the HexDumpProxyFrontendHandler class in HexDumpProxyFrontendHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00["HexDumpProxyFrontendHandler"] e8fde6e1_d43b_836d_89a0_368f6b899d08["HexDumpProxyFrontendHandler.java"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|defined in| e8fde6e1_d43b_836d_89a0_368f6b899d08 c76768e7_0bf2_2d26_99f8_733016829149["HexDumpProxyFrontendHandler()"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|method| c76768e7_0bf2_2d26_99f8_733016829149 b686feee_4b89_df87_c94c_c0ccf70e36a4["channelActive()"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|method| b686feee_4b89_df87_c94c_c0ccf70e36a4 c4be76b7_7ccb_f9da_149d_0391de410b3f["channelRead()"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|method| c4be76b7_7ccb_f9da_149d_0391de410b3f 1fe7e03e_74b7_196b_ef16_83238d8b726e["channelInactive()"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|method| 1fe7e03e_74b7_196b_ef16_83238d8b726e aac00a87_48d9_2e79_ec43_e8531cf4514e["exceptionCaught()"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|method| aac00a87_48d9_2e79_ec43_e8531cf4514e 4f399dc4_2724_265c_7b7d_ab360f901458["closeOnFlush()"] 80e1dfc5_bd72_03a2_6186_6a50f3a5bb00 -->|method| 4f399dc4_2724_265c_7b7d_ab360f901458
Relationship Graph
Source Code
example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java lines 27–99
public class HexDumpProxyFrontendHandler extends ChannelInboundHandlerAdapter {
private final String remoteHost;
private final int remotePort;
// As we use inboundChannel.eventLoop() when building the Bootstrap this does not need to be volatile as
// the outboundChannel will use the same EventLoop (and therefore Thread) as the inboundChannel.
private Channel outboundChannel;
public HexDumpProxyFrontendHandler(String remoteHost, int remotePort) {
this.remoteHost = remoteHost;
this.remotePort = remotePort;
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
final Channel inboundChannel = ctx.channel();
// Start the connection attempt.
Bootstrap b = new Bootstrap();
b.group(inboundChannel.eventLoop())
.channel(ctx.channel().getClass())
.handler(new HexDumpProxyBackendHandler(inboundChannel))
.option(ChannelOption.AUTO_READ, false);
ChannelFuture f = b.connect(remoteHost, remotePort);
outboundChannel = f.channel();
f.addListener(future -> {
if (future.isSuccess()) {
// connection complete start to read first data
inboundChannel.read();
} else {
// Close the connection if the connection attempt has failed.
inboundChannel.close();
}
});
}
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
if (outboundChannel.isActive()) {
outboundChannel.writeAndFlush(msg).addListener(future -> {
if (future.isSuccess()) {
// was able to flush out data, start to read the next chunk
ctx.read();
} else {
ctx.close();
}
});
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
if (outboundChannel != null) {
closeOnFlush(outboundChannel);
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
closeOnFlush(ctx.channel());
}
/**
* Closes the specified channel after all queued write requests are flushed.
*/
static void closeOnFlush(Channel ch) {
if (ch.isActive()) {
ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
}
}
Source
Frequently Asked Questions
What is the HexDumpProxyFrontendHandler class?
HexDumpProxyFrontendHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java.
Where is HexDumpProxyFrontendHandler defined?
HexDumpProxyFrontendHandler is defined in example/src/main/java/io/netty/example/proxy/HexDumpProxyFrontendHandler.java at line 27.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free