当前位置: 首页>>代码示例>>Java>>正文


Java ServerBootstrap.option方法代码示例

本文整理汇总了Java中io.netty.bootstrap.ServerBootstrap.option方法的典型用法代码示例。如果您正苦于以下问题:Java ServerBootstrap.option方法的具体用法?Java ServerBootstrap.option怎么用?Java ServerBootstrap.option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.bootstrap.ServerBootstrap的用法示例。


在下文中一共展示了ServerBootstrap.option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void start(SlaveNode slaveNode) {
    if(slaveNode==null){
        throw new IllegalArgumentException("slaveNode is null");
    }
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new SlaveServerInitializer());

        ChannelFuture future = b.bind(slaveNode.getPort()).sync();
        LOGGER.info("SlaveServer Startup at port:{}",slaveNode.getPort());

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:27,代码来源:SlaveServer.java

示例2: start

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new MasterServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        LOGGER.info("MasterServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:MasterServer.java

示例3: start

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new ServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        logger.info("NettyServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:NettyServer.java

示例4: doOpen

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void doOpen() throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try{
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup,workerGroup);
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
            protected void initChannel(SocketChannel socketChannel) throws Exception {
                ChannelPipeline pipeline = socketChannel.pipeline();
                pipeline.addLast(new ObjectDecoder(1024*1024, ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));
                pipeline.addLast(new ObjectEncoder());
                pipeline.addLast((SimpleChannelInboundHandler)handler);
            }
        });
        serverBootstrap.option(ChannelOption.SO_BACKLOG,1024);
        serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE,true);
        ChannelFuture future = serverBootstrap.bind(address,port).sync();
        //future.channel().closeFuture().sync();
    }finally{
        //workerGroup.shutdownGracefully();
        //bossGroup.shutdownGracefully();
    }
}
 
开发者ID:dachengxi,项目名称:mini-dubbo,代码行数:25,代码来源:NettyServer.java

示例5: run

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void run() {
    try {
        // Configure the server.
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.option(ChannelOption.SO_BACKLOG, 1024);
            b.group(group)
                    .channel(NioServerSocketChannel.class)
                    .handler(new LoggingHandler(LogLevel.INFO))
                    .childHandler(new Http2ServerInitializer(mSslCtx));

            sServerChannel = b.bind(PORT).sync().channel();
            Log.i(TAG, "Netty HTTP/2 server started on " + getServerUrl());
            sBlock.open();
            sServerChannel.closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
        Log.i(TAG, "Stopped Http2TestServerRunnable!");
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:25,代码来源:Http2TestServer.java

示例6: startAcceptingConnections

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.SO_RCVBUF, 1048576);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.group(serverGroup, clientGroup);
    b.channel(serverChannelClass);
    if (enableNettyTls) {
        b.childHandler(new SslServerCommunicationChannelInitializer());
    } else {
        b.childHandler(new OnosCommunicationChannelInitializer());
    }
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);

    // Bind and start to accept incoming connections.
    b.bind(localEp.port()).sync().addListener(future -> {
        if (future.isSuccess()) {
            log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port());
        } else {
            log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause());
        }
    });
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:NettyMessagingManager.java

示例7: startNotificationRegisterEndpoint

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
protected void startNotificationRegisterEndpoint(final String host, final int port) {

        Runnable notificationRegisterEndpointRunnable = new Runnable() {

            @Override
            public void run() {
                bossGroup = new NioEventLoopGroup(1);
                workerGroup = new NioEventLoopGroup();

                try {
                    ServerBootstrap b = new ServerBootstrap();
                    b.option(ChannelOption.SO_BACKLOG, 1024);
                    b.group(bossGroup, workerGroup)
                        .channel(NioServerSocketChannel.class)
                        .handler(new LoggingHandler(LogLevel.INFO))
                        .childHandler(new NotificationRegisterServerInitializer());

                    Channel ch = b.bind(host, port).sync().channel();

                    logger.info(String.format("Notification register endpoint started at %s:%s", host, port));

                    ch.closeFuture().sync();
                } catch (InterruptedException ex) {
                    logger.info("Notification register endpoint was interrupted.");
                } finally {
                    bossGroup.shutdownGracefully();
                    workerGroup.shutdownGracefully();
                }

            }
        };

        notificationEndpointThread = new Thread(notificationRegisterEndpointRunnable);
        notificationEndpointThread.start();
    }
 
开发者ID:aerogear,项目名称:push-network-proxies,代码行数:36,代码来源:NotificationRegisterEndpoint.java

示例8: main

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // Configure SSL.
    //final SslContext sslCtx;
    ConfigurationManager.getConfigInstance().setProperty("app.localLog.path","E:\\Tools\\apache-tomcat-7.0.68\\logs");

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new HttpHelloWorldServerInitializer());


        Channel ch = b.bind(PORT).sync().channel();



        System.err.println("Open your web browser and navigate to " +
                (SSL? "https" : "http") + "://127.0.0.1:" + PORT + '/');

        ch.closeFuture().sync();

    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:32,代码来源:HttpHelloWorldServer.java

示例9: setUserOpt

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
private <O> void setUserOpt(ServerBootstrap boot, ChannelOption<O> opt, O value) {
    if (value != null) {
        if (DEBUG) {
            log.debug("Setting option {} = {} [address={}]", opt, value, address);
        }

        boot.option(opt, value);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:10,代码来源:NettyServer.java

示例10: start

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void start() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_LINGER, socketLinger);
    b.option(ChannelOption.SO_REUSEADDR, reuseAddress);
    b.group(bossGroup, workerGroup)
        .channel(NioServerSocketChannel.class)
        .handler(new LoggingHandler(LogLevel.INFO))
        .childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                p.addLast(new HttpRequestDecoder());
                p.addLast(new HttpObjectAggregator(1024 * 1024 * 5));
                p.addLast(new HttpResponseEncoder());
                p.addLast(new HttpContentCompressor());
                if (corsConfiguration.hasHeader()) {
                    p.addLast(new CorsHandler(
                        CorsConfig
                            .withOrigin(corsConfiguration.getHeader())
                            .allowedRequestHeaders(HttpHeaders.Names.CONTENT_TYPE)
                            .allowedRequestMethods(HttpMethod.POST)
                        .build())
                    );
                }
                p.addLast(jsonRpcWeb3FilterHandler);
                p.addLast(jsonRpcWeb3ServerHandler);
            }
        });
    b.bind(host, port).sync();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:31,代码来源:JsonRpcNettyServer.java

示例11: start

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void start(int port) {
    // TODO review listening use
    listening = true;

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

    EthereumChannelInitializer ethereumChannelInitializer = ethereumChannelInitializerFactory.newInstance("");

    ethereumListener.trace("Listening on port " + port);


    try {
        ServerBootstrap b = new ServerBootstrap();

        b.group(bossGroup, workerGroup);
        b.channel(NioServerSocketChannel.class);

        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
        b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerConnectionTimeout());

        b.handler(new LoggingHandler());
        b.childHandler(ethereumChannelInitializer);

        // Start the client.
        logger.info("Listening for incoming connections, port: [{}] ", port);
        logger.info("NodeId: [{}] ", Hex.toHexString(config.nodeId()));

        ChannelFuture f = b.bind(port).sync();

        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
        logger.debug("Connection is closed");

        // TODO review listening use
        listening = false;
    } catch (Exception e) {
        logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
        throw new Error("Server Disconnected");
    } finally {
        workerGroup.shutdownGracefully();

    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:46,代码来源:PeerServerImpl.java

示例12: startSocket

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void startSocket() throws InterruptedException {
    EventLoopGroup boss = new NioEventLoopGroup();
    EventLoopGroup worker = new NioEventLoopGroup();

    try {
        ServerBootstrap boot = new ServerBootstrap();
        boot.group(boss,worker);

        boot.channel(NioServerSocketChannel.class);
        boot.childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024*1024,0,4,-4,0,false));
                ch.pipeline().addLast(new ByteToPacketCodec());
                //ch.pipeline().addLast(new LoginChannelHandler(listener));
                ch.pipeline().addLast(new PacketChannelHandler(listener));
            }
        });

        boot.option(ChannelOption.SO_BACKLOG,128);
        boot.childOption(ChannelOption.SO_KEEPALIVE,true);
        channelFuture = boot.bind(port).sync();
        System.out.println("服务器"+port+"开启成功...");
        channelFuture.channel().closeFuture().sync();
    }finally {
        boss.shutdownGracefully().sync();
        worker.shutdownGracefully().sync();
        channelFuture = null;
        System.out.println("服务器关闭成功...");
    }
}
 
开发者ID:werewolfKill,项目名称:werewolf_server,代码行数:32,代码来源:ThreadServerSocket.java

示例13: main

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new HttpHelloWorldServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        System.err.println("Open your web browser and navigate to " +
                (SSL? "https" : "http") + "://127.0.0.1:" + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:avirtuos,项目名称:teslog,代码行数:33,代码来源:HttpHelloWorldServer.java

示例14: startAcceptingConnections

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
/**
 * Accepts incoming connections.
 */
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();

    b.group(bossGroup, workerGroup).channel(serverChannelClass)
            .childHandler(new OnosCommunicationChannelInitializer());
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);
    b.bind(ovsdbPort).sync();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:Controller.java

示例15: run

import io.netty.bootstrap.ServerBootstrap; //导入方法依赖的package包/类
public void run() {
	ServerBootstrap b = new ServerBootstrap();// 引导辅助程序

	bossGroup = new NioEventLoopGroup(BIZGROUPSIZE);
	workerGroup = new NioEventLoopGroup(BIZTHREADSIZE);
	try {
		b.group(bossGroup, workerGroup);
		b.channel(NioServerSocketChannel.class);// 设置nio类型的channel
		b.childHandler(new ChannelInitializer<SocketChannel>() {// 有连接到达时会创建一个channel
			protected void initChannel(SocketChannel ch) throws Exception {
				logger.debug("客户端:{} 初始化", ch.remoteAddress());
				// pipeline管理channel中的Handler,在channel队列中添加一个handler来处理业务
				ch.pipeline().addLast("frameDecoder",
						new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
				ch.pipeline().addLast("frameEncoder", new LengthFieldPrepender(4));
				ch.pipeline().addLast("decoder", msgPackDecode);
				ch.pipeline().addLast("encoder", msgPackEncode);
				ch.pipeline().addLast(serverHandler);
			}
		});
		b.option(ChannelOption.SO_BACKLOG, 128);
		b.childOption(ChannelOption.SO_KEEPALIVE, true);
		logger.info("server start : {}", port);
		ChannelFuture f = b.bind(port).sync();// 配置完成,开始绑定server,通过调用sync同步方法阻塞直到绑定成功
		channel = f.channel();
		f.channel().closeFuture().sync();// 应用程序会一直等待,直到channel关闭
	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
开发者ID:ctodb,项目名称:push,代码行数:32,代码来源:MgsServer.java


注:本文中的io.netty.bootstrap.ServerBootstrap.option方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。