Home / Class/ FileServer Class — netty Architecture

FileServer Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f9408ae3_c023_c3c2_b455_24cf0c286524["FileServer"]
  976cdff5_d7c8_3cb4_13ba_679b920d9879["FileServer.java"]
  f9408ae3_c023_c3c2_b455_24cf0c286524 -->|defined in| 976cdff5_d7c8_3cb4_13ba_679b920d9879
  a7a95493_2c84_46cf_0735_b7603abcd1fa["main()"]
  f9408ae3_c023_c3c2_b455_24cf0c286524 -->|method| a7a95493_2c84_46cf_0735_b7603abcd1fa

Relationship Graph

Source Code

example/src/main/java/io/netty/example/file/FileServer.java lines 41–85

public final class FileServer {

    static final boolean SSL = System.getProperty("ssl") != null;
    // Use the same default port with the telnet example so that we can use the telnet client example to access it.
    static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8992" : "8023"));

    public static void main(String[] args) throws Exception {
        // Configure SSL.
        final SslContext sslCtx = ServerUtil.buildSslContext();

        // Configure the server.
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.group(group)
             .channel(NioServerSocketChannel.class)
             .option(ChannelOption.SO_BACKLOG, 100)
             .handler(new LoggingHandler(LogLevel.INFO))
             .childHandler(new ChannelInitializer<SocketChannel>() {
                 @Override
                 public void initChannel(SocketChannel ch) throws Exception {
                     ChannelPipeline p = ch.pipeline();
                     if (sslCtx != null) {
                         p.addLast(sslCtx.newHandler(ch.alloc()));
                     }
                     p.addLast(
                             new StringEncoder(CharsetUtil.UTF_8),
                             new LineBasedFrameDecoder(8192),
                             new StringDecoder(CharsetUtil.UTF_8),
                             new ChunkedWriteHandler(),
                             new FileServerHandler());
                 }
             });

            // Start the server.
            ChannelFuture f = b.bind(PORT).sync();

            // Wait until the server socket is closed.
            f.channel().closeFuture().sync();
        } finally {
            // Shut down all event loops to terminate all threads.
            group.shutdownGracefully();
        }
    }
}

Frequently Asked Questions

What is the FileServer class?
FileServer is a class in the netty codebase, defined in example/src/main/java/io/netty/example/file/FileServer.java.
Where is FileServer defined?
FileServer is defined in example/src/main/java/io/netty/example/file/FileServer.java at line 41.

Analyze Your Own Codebase

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

Try Supermodel Free