IpSubnetFilterExample Class — netty Architecture
Architecture documentation for the IpSubnetFilterExample class in IpSubnetFilterExample.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b2f7b3cc_38d0_dcce_66c2_e53544bef76b["IpSubnetFilterExample"] 4eabfdf8_4e38_d741_fa18_69070a473b48["IpSubnetFilterExample.java"] b2f7b3cc_38d0_dcce_66c2_e53544bef76b -->|defined in| 4eabfdf8_4e38_d741_fa18_69070a473b48 7471e9cd_216c_b2e8_18b1_082a03485990["main()"] b2f7b3cc_38d0_dcce_66c2_e53544bef76b -->|method| 7471e9cd_216c_b2e8_18b1_082a03485990
Relationship Graph
Source Code
example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java lines 42–89
public final class IpSubnetFilterExample {
static final int PORT = Integer.parseInt(System.getProperty("port", "8009"));
public static void main(String[] args) throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
List<IpSubnetFilterRule> rules = new ArrayList<IpSubnetFilterRule>();
// Reject 10.10.10.0/24 and 192.168.0.0/16 ranges but accept the rest
rules.add(new IpSubnetFilterRule("10.10.10.0", 24, IpFilterRuleType.REJECT));
rules.add(new IpSubnetFilterRule("192.168.0.0", 16, IpFilterRuleType.REJECT));
// Share this same Handler instance with multiple ChannelPipeline(s).
final IpSubnetFilter ipFilter = new IpSubnetFilter(rules);
ServerBootstrap b = new ServerBootstrap();
b.group(group)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addFirst(ipFilter);
p.addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
System.out.println("Received data from: " + ctx.channel().remoteAddress());
}
});
}
});
// Bind and start to accept incoming connections.
ChannelFuture f = b.bind(PORT).sync();
// Wait until the server socket is closed.
// In this example, this does not happen, but you can do that to gracefully
// shut down your server.
f.channel().closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
}
Source
Frequently Asked Questions
What is the IpSubnetFilterExample class?
IpSubnetFilterExample is a class in the netty codebase, defined in example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java.
Where is IpSubnetFilterExample defined?
IpSubnetFilterExample is defined in example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java at line 42.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free