Home / Class/ LocalEcho Class — netty Architecture

LocalEcho Class — netty Architecture

Architecture documentation for the LocalEcho class in LocalEcho.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  8c7676e0_f02c_c614_6310_e90f05019698["LocalEcho"]
  0276c476_22ee_d950_8bc5_12cf304bfeae["LocalEcho.java"]
  8c7676e0_f02c_c614_6310_e90f05019698 -->|defined in| 0276c476_22ee_d950_8bc5_12cf304bfeae
  6d2fdd87_7b09_8a93_f218_2a095e48312f["main()"]
  8c7676e0_f02c_c614_6310_e90f05019698 -->|method| 6d2fdd87_7b09_8a93_f218_2a095e48312f

Relationship Graph

Source Code

example/src/main/java/io/netty/example/localecho/LocalEcho.java lines 35–108

public final class LocalEcho {

    static final String PORT = System.getProperty("port", "test_port");

    public static void main(String[] args) throws Exception {
        // Address to bind on / connect to.
        final LocalAddress addr = new LocalAddress(PORT);

        EventLoopGroup serverGroup = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory());
        EventLoopGroup clientGroup =  new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory());
        try {
            // Note that we can use any event loop to ensure certain local channels
            // are handled by the same event loop thread which drives a certain socket channel
            // to reduce the communication latency between socket channels and local channels.
            ServerBootstrap sb = new ServerBootstrap();
            sb.group(serverGroup)
              .channel(LocalServerChannel.class)
              .handler(new ChannelInitializer<LocalServerChannel>() {
                  @Override
                  public void initChannel(LocalServerChannel ch) throws Exception {
                      ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
                  }
              })
              .childHandler(new ChannelInitializer<LocalChannel>() {
                  @Override
                  public void initChannel(LocalChannel ch) throws Exception {
                      ch.pipeline().addLast(
                              new LoggingHandler(LogLevel.INFO),
                              new LocalEchoServerHandler());
                  }
              });

            Bootstrap cb = new Bootstrap();
            cb.group(clientGroup)
              .channel(LocalChannel.class)
              .handler(new ChannelInitializer<LocalChannel>() {
                  @Override
                  public void initChannel(LocalChannel ch) throws Exception {
                      ch.pipeline().addLast(
                              new LoggingHandler(LogLevel.INFO),
                              new LocalEchoClientHandler());
                  }
              });

            // Start the server.
            sb.bind(addr).sync();

            // Start the client.
            Channel ch = cb.connect(addr).sync().channel();

            // Read commands from the stdin.
            System.out.println("Enter text (quit to end)");
            ChannelFuture lastWriteFuture = null;
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            for (;;) {
                String line = in.readLine();
                if (line == null || "quit".equalsIgnoreCase(line)) {
                    break;
                }

                // Sends the received line to the server.
                lastWriteFuture = ch.writeAndFlush(line);
            }

            // Wait until all messages are flushed before closing the channel.
            if (lastWriteFuture != null) {
                lastWriteFuture.awaitUninterruptibly();
            }
        } finally {
            serverGroup.shutdownGracefully();
            clientGroup.shutdownGracefully();
        }
    }
}

Frequently Asked Questions

What is the LocalEcho class?
LocalEcho is a class in the netty codebase, defined in example/src/main/java/io/netty/example/localecho/LocalEcho.java.
Where is LocalEcho defined?
LocalEcho is defined in example/src/main/java/io/netty/example/localecho/LocalEcho.java at line 35.

Analyze Your Own Codebase

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

Try Supermodel Free