Home / Function/ main() — netty Function Reference

main() — netty Function Reference

Architecture documentation for the main() function in IpSubnetFilterExample.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7471e9cd_216c_b2e8_18b1_082a03485990["main()"]
  b2f7b3cc_38d0_dcce_66c2_e53544bef76b["IpSubnetFilterExample"]
  7471e9cd_216c_b2e8_18b1_082a03485990 -->|defined in| b2f7b3cc_38d0_dcce_66c2_e53544bef76b
  style 7471e9cd_216c_b2e8_18b1_082a03485990 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java lines 46–88

    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();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does main() do?
main() is a function in the netty codebase, defined in example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java.
Where is main() defined?
main() is defined in example/src/main/java/io/netty/example/ipfilter/IpSubnetFilterExample.java at line 46.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free