Package io.netty.bootstrap

Examples of io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor


  public void start() {
    int port = ErraiConfigAttribs.WEB_SOCKET_PORT.getInt(svc.getConfiguration());

    // Configure the server.
    final ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

    final WebSocketServerPipelineFactory factory = new WebSocketServerPipelineFactory(svc);

    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(factory);

    // Bind and start to accept incoming connections.
    final Channel server = bootstrap.bind(new InetSocketAddress(port));

    svc.addShutdownHook(new Runnable() {
      @Override
      public void run() {
        bootstrap.releaseExternalResources();
        factory.getWebSocketServerHandler().stop();
        server.close();
        svc = null;
        log.info("web socket server stopped.");
      }
View Full Code Here


    public Server(ServerEnvironment env) {
        this.serverEnvironment = env;

        this.logger.info("Bootstrapping server");

        this.serverBootstrap = new ServerBootstrap();

        this.boss = new NioEventLoopGroup();
        this.worker = new NioEventLoopGroup();

        this.serverBootstrap.group(this.boss, this.worker)
View Full Code Here

        this.addr = addr;
        this.port = port;
    }

    public void listen(int backlog) {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(this.process.getEventLoop().getEventLoopGroup());
        bootstrap.channel(NioServerSocketChannel.class);
        bootstrap.childHandler(new ChannelInitializer<Channel>() {
            @Override
            protected void initChannel(Channel ch) throws Exception {
                ch.config().setAutoRead(false);
//                ch.pipeline().addLast("debug", new DebugHandler("server"));
                ch.pipeline().addLast("emit.connection", new ConnectionEventHandler(TCPWrap.this.process, TCPWrap.this));
                ch.pipeline().addLast("handle", new UnrefHandler(TCPWrap.this));
            }
        });
        this.channelFuture = bootstrap.bind(this.addr, this.port);
        this.channelFuture.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                // TODO callback error
            }
View Full Code Here

    /**
     * {@inheritDoc}
     * @throws 
     */
    public void start(int port) throws IOException {
        ServerBootstrap bootstrap = null;
        ;

        try {
            bootstrap = new ServerBootstrap();
            bootstrap.option(ChannelOption.SO_RCVBUF, 128 * 1024);
            bootstrap.option(ChannelOption.TCP_NODELAY, true);
            bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup());
            bootstrap.channel(NioServerSocketChannel.class);
            bootstrap.localAddress(port);
            bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel channel) throws Exception {
                    channel.pipeline().addLast(new TestServerHandler());
                };
            });
            ChannelFuture bindFuture = bootstrap.bind();
            bindFuture.sync();
            Channel channel = bindFuture.channel();
            ChannelFuture closeFuture = channel.closeFuture();
            //closeFuture.sync();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            bootstrap.shutdown();
        }
    }
View Full Code Here

     * {@inheritDoc}
     * @throws 
     */
    public void start(int port) throws IOException {
        try {
            bootstrap = new ServerBootstrap();
            bootstrap.option(ChannelOption.SO_RCVBUF, 128 * 1024);
            bootstrap.option(ChannelOption.TCP_NODELAY, true);
            bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup());
            bootstrap.channel(NioServerSocketChannel.class);
            bootstrap.localAddress(port);
View Full Code Here

      // Report metrics via JMX
      jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
      jmxReporter.start();

      new ServerBootstrap().group(eventLoopGroup).channel(NioServerSocketChannel.class)
          .option(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.SO_KEEPALIVE, true)
          .childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel socketChannel) throws Exception {
              socketChannel.pipeline().addLast(
View Full Code Here

  public BasicServer(RpcConfig rpcMapping, ByteBufAllocator alloc, EventLoopGroup eventLoopGroup) {
    super(rpcMapping);
    this.eventLoopGroup = eventLoopGroup;
   
    b = new ServerBootstrap() //
        .channel(NioServerSocketChannel.class) //
        .option(ChannelOption.SO_BACKLOG, 100) //
        .option(ChannelOption.SO_RCVBUF, 1 << 17) //
        .option(ChannelOption.SO_SNDBUF, 1 << 17) //
        .group(eventLoopGroup) //
View Full Code Here

        Class channelClass = NioServerSocketChannel.class;
        if (configCopy.isUseLinuxNativeEpoll()) {
            channelClass = EpollServerSocketChannel.class;
        }

        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
        .channel(channelClass)
        .childHandler(pipelineFactory);
        applyConnectionOptions(b);

        InetSocketAddress addr = new InetSocketAddress(configCopy.getPort());
        if (configCopy.getHostname() != null) {
            addr = new InetSocketAddress(configCopy.getHostname(), configCopy.getPort());
        }

        return b.bind(addr).addListener(new FutureListener<Void>() {
            @Override
            public void operationComplete(Future<Void> future) throws Exception {
                if (future.isSuccess()) {
                    log.info("SocketIO server started at port: {}", configCopy.getPort());
                } else {
View Full Code Here

    // Only execute the command handler in a single thread
    final RedisCommandHandler commandHandler = new RedisCommandHandler(new SimpleRedisServer());

    // Configure the server.
    ServerBootstrap b = new ServerBootstrap();
    final DefaultEventExecutorGroup group = new DefaultEventExecutorGroup(1);
    try {
        b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
         .channel(NioServerSocketChannel.class)
         .option(ChannelOption.SO_BACKLOG, 100)
         .localAddress(port)
         .childOption(ChannelOption.TCP_NODELAY, true)
         .childHandler(new ChannelInitializer<SocketChannel>() {
           @Override
           public void initChannel(SocketChannel ch) throws Exception {
             ChannelPipeline p = ch.pipeline();
//             p.addLast(new ByteLoggingHandler(LogLevel.INFO));
             p.addLast(new RedisCommandDecoder());
             p.addLast(new RedisReplyEncoder());
             p.addLast(group, commandHandler);
           }
         });

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

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

    public CubeServer start() {
        workerGroup = new NioEventLoopGroup(8);

        try {
            final ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap
                .option(ChannelOption.SO_REUSEADDR, true)
                .option(ChannelOption.SO_SNDBUF, 1024)
                .option(ChannelOption.TCP_NODELAY, true)
                .group(workerGroup)
                .channel(NioServerSocketChannel.class)
View Full Code Here

TOP

Related Classes of io.netty.bootstrap.ServerBootstrap$ServerBootstrapAcceptor

Copyright © 2018 www.massapicom. 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.