Package org.springframework.sandbox.netty

Source Code of org.springframework.sandbox.netty.MyServer

package org.springframework.sandbox.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class MyServer {

  private final int port;

  public MyServer(int port) {
    this.port = port;
  }

  public void run() throws Exception {
    ServerBootstrap server = new ServerBootstrap();
    try {
      server.group(new NioEventLoopGroup(), new NioEventLoopGroup())
          .channel(NioServerSocketChannel.class).localAddress(port)
          .childHandler(new DispatcherServletChannelInitializer());

      server.bind().sync().channel().closeFuture().sync();
    }
    finally {
      server.shutdown();
    }
  }

  public static void main(String[] args) throws Exception {
    int port;
    if (args.length > 0) {
      port = Integer.parseInt(args[0]);
    } else {
      port = 8080;
    }
    new MyServer(port).run();
  }
}
TOP

Related Classes of org.springframework.sandbox.netty.MyServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.