Package io.netty.channel.nio

Examples of io.netty.channel.nio.NioEventLoopGroup


            return;
        }

        // Configure the server.
        eventExecutorGroup = new RequestThreadPoolExecutor();
        workerGroup = new NioEventLoopGroup();

        ServerBootstrap bootstrap = new ServerBootstrap()
                                    .group(workerGroup)
                                    .channel(NioServerSocketChannel.class)
                                    .childOption(ChannelOption.TCP_NODELAY, true)
View Full Code Here


    /**
     * Start Gremlin Server with {@link Settings} provided to the constructor.
     */
    public void run() throws Exception {
        final EventLoopGroup bossGroup = new NioEventLoopGroup(settings.threadPoolBoss);
        final EventLoopGroup workerGroup = new NioEventLoopGroup(settings.threadPoolWorker);

        final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("gremlin-%d").build();
        final EventExecutorGroup gremlinGroup = new DefaultEventExecutorGroup(settings.gremlinPool, threadFactory);

        try {
            final ServerBootstrap b = new ServerBootstrap();

            // when high value is reached then the channel becomes non-writeable and stays like that until the
            // low value is so that there is time to recover
            b.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, settings.writeBufferLowWaterMark);
            b.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, settings.writeBufferHighWaterMark);
            b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

            final GremlinExecutor gremlinExecutor = initializeGremlinExecutor(gremlinGroup, workerGroup);
            final Channelizer channelizer = createChannelizer(settings);
            channelizer.init(settings, gremlinExecutor, gremlinGroup, graphs.get(), workerGroup);
            b.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(channelizer);

            ch = b.bind(settings.host, settings.port).sync().channel();
            logger.info("Gremlin Server configured with worker thread pool of {} and boss thread pool of {}",
                    settings.threadPoolWorker, settings.threadPoolBoss);
            logger.info("Channel started at port {}.", settings.port);

            serverReady.ifPresent(future -> future.complete(null));

            ch.closeFuture().sync();
        } finally {
            logger.info("Shutting down thread pools");

            gremlinGroup.shutdownGracefully();
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();

            logger.info("Gremlin Server - shutdown complete");
        }
    }
View Full Code Here

        this(URI.create("gs://localhost:8182"));
    }

    public NioClient(final URI uri) {
        final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("nio-client-%d").build();
        group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), threadFactory);
        final Bootstrap b = new Bootstrap().group(group);

        try {
            final MessageSerializer serializer = new KryoMessageSerializerV1d0();
            b.channel(NioSocketChannel.class)
View Full Code Here

        this(URI.create("ws://localhost:8182"));
    }

    public WebSocketClient(final URI uri) {
        final BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("ws-client-%d").build();
        group = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), threadFactory);
        final Bootstrap b = new Bootstrap().group(group);

        final String protocol = uri.getScheme();
        if (!"ws".equals(protocol))
            throw new IllegalArgumentException("Unsupported protocol: " + protocol);
View Full Code Here

   
    public NettyHttpConduit(Bus b, EndpointInfo ei, EndpointReferenceType t, NettyHttpConduitFactory conduitFactory)
        throws IOException {
        super(b, ei, t);
        factory = conduitFactory;
        group = new NioEventLoopGroup();
        bootstrap = new Bootstrap();
        bootstrap.group(group);
        bootstrap.channel(NioSocketChannel.class);
    }
View Full Code Here

    /**
     * Creates a new boss pool.
     */
    EventLoopGroup build() {
        return new NioEventLoopGroup(bossCount, new CamelThreadFactory(pattern, name, false));
    }
View Full Code Here

    /**
     * Creates a new worker pool.
     */
    public EventLoopGroup build() {
        int count = workerCount > 0 ? workerCount : NettyHelper.DEFAULT_IO_THREADS;
        workerPool = new NioEventLoopGroup(count, new CamelThreadFactory(pattern, name, false));
        return workerPool;
    }
View Full Code Here

  public static EventLoopGroup createEventLoopGroup(int nThreads, String prefix) {
     if(SUPPORTS_EPOLL){
       return new EpollEventLoopGroup(nThreads, new NamedThreadFactory(prefix));
     }else{
       return new NioEventLoopGroup(nThreads, new NamedThreadFactory(prefix));
     }
  }
View Full Code Here

    public Server(int port) {
        this.port = port;

        server = new LobbyServer(this);

        bossGroup = new NioEventLoopGroup();
        workerGroup = new NioEventLoopGroup();

        if (DEBUG_SEND) {
            logger.setLevel(Level.ALL);
        }
    }
View Full Code Here

    final int port = ErraiConfigAttribs.WEB_SOCKET_PORT.getInt(esc);
    final ServerBootstrap bootstrap = new ServerBootstrap();
    final WebSocketServerHandler webSocketHandler = new WebSocketServerHandler(svc);

    try {
      final NioEventLoopGroup bossGroup = new NioEventLoopGroup();
      final NioEventLoopGroup workerGroup = new NioEventLoopGroup();
      final ChannelFuture channelFuture = bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
              .childHandler(new ChannelInitializer() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                  if (useSecureWebSocket) {
                    final SslHandler sslHandler = SslHandlerFactory.buildSslHandler(esc);
                    ch.pipeline().addLast("ssl", sslHandler);
                  }
                  ch.pipeline().addLast("codec-http", new HttpServerCodec());
                  ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));
                  ch.pipeline().addLast("handler", webSocketHandler);
                }

              }).bind(port).sync();

      svc.addShutdownHook(new Runnable() {
        @Override
        public void run() {
          try {
            webSocketHandler.stop();
            channelFuture.channel().close();
            log.info("web socket server stopped.");
          }
          catch (Exception e) {
            throw new RuntimeException(e);
          }
          finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
          }
        }
      });

    }
View Full Code Here

TOP

Related Classes of io.netty.channel.nio.NioEventLoopGroup

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.