本文整理匯總了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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
}
示例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());
}
});
}
示例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();
}
示例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();
}
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例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("服務器關閉成功...");
}
}
示例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();
}
}
示例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();
}
示例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();
}
}