本文整理匯總了Java中io.netty.bootstrap.ServerBootstrap.handler方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerBootstrap.handler方法的具體用法?Java ServerBootstrap.handler怎麽用?Java ServerBootstrap.handler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.bootstrap.ServerBootstrap
的用法示例。
在下文中一共展示了ServerBootstrap.handler方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: start
import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start() throws Exception {
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(boss, worker);
bootstrap.channel(NioServerSocketChannel.class);
bootstrap.handler(new LoggingHandler(LogLevel.INFO));
bootstrap.childHandler(ProxyServerChannelInitializerFactory.getChannelInitializer(definition));
bootstrap.childOption(ChannelOption.AUTO_READ, false);
bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
server = bootstrap.bind(port).sync().channel();
log.info("Started proxy server at port: " + port);
} catch (Exception e) {
log.error(String.format("Failed starting proxy server at port: %d", port), e);
}
}
示例3: start
import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start(int port) {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
ethereumChannelInitializer = ctx.getBean(EthereumChannelInitializer.class, "");
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 = b.bind(port).sync();
listening = true;
// Wait until the connection is closed.
channelFuture.channel().closeFuture().sync();
logger.debug("Connection is closed");
} catch (Exception e) {
logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
throw new Error("Server Disconnected");
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
listening = false;
}
}