本文整理匯總了Java中org.jboss.netty.bootstrap.ServerBootstrap.setOption方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerBootstrap.setOption方法的具體用法?Java ServerBootstrap.setOption怎麽用?Java ServerBootstrap.setOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.bootstrap.ServerBootstrap
的用法示例。
在下文中一共展示了ServerBootstrap.setOption方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
/**
* Tell controller that we're ready to accept pcc connections.
*/
public void run() {
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new PcepPipelineFactory(this);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(pcepPort);
cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
log.info("Listening for PCC connection on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: NettyServerCnxnFactory
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
NettyServerCnxnFactory() {
bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// parent channel
bootstrap.setOption("reuseAddress", true);
// child channels
bootstrap.setOption("child.tcpNoDelay", true);
/* set socket linger to off, so that socket close does not block */
bootstrap.setOption("child.soLinger", -1);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline p = Channels.pipeline();
if (secure) {
initSSL(p);
}
p.addLast("servercnxnfactory", channelHandler);
return p;
}
});
}
示例3: run
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
/**
* Tell controller that we're ready to accept switches loop.
*/
public void run() {
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact =
new OpenflowPipelineFactory(this, null, sslContext);
bootstrap.setPipelineFactory(pfact);
cg = new DefaultChannelGroup();
openFlowPorts.forEach(port -> {
InetSocketAddress sa = new InetSocketAddress(port);
cg.add(bootstrap.bind(sa));
log.info("Listening for switch connections on {}", sa);
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: start
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
@Override
public void start() throws KairosDBException
{
// Configure the server.
serverBootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-boss-%d").build()),
Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-worker-%d").build())));
// Configure the pipeline factory.
serverBootstrap.setPipelineFactory(this);
serverBootstrap.setOption("child.tcpNoDelay", true);
serverBootstrap.setOption("child.keepAlive", true);
serverBootstrap.setOption("reuseAddress", true);
// Bind and start to accept incoming connections.
serverBootstrap.bind(new InetSocketAddress(address, port));
}
示例5: bootstrapNetty
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
/**
* Bootstraps netty, the server that handles all openflow connections
*/
public void bootstrapNetty() {
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = useSsl ? new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, keyStore, keyStorePassword) :
new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(floodlightProvider.getOFPort());
final ChannelGroup cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
log.info("Listening for switch connections on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: NettyServerCnxnFactory
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
NettyServerCnxnFactory() {
bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// parent channel
bootstrap.setOption("reuseAddress", true);
// child channels
bootstrap.setOption("child.tcpNoDelay", true);
/* set socket linger to off, so that socket close does not block */
bootstrap.setOption("child.soLinger", -1);
bootstrap.getPipeline().addLast("servercnxnfactory", channelHandler);
}
示例7: run
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
/**
* Tell controller that we're ready to accept bgp peer connections.
*/
public void run() {
try {
peerBootstrap = createPeerBootStrap();
peerBootstrap.setOption("reuseAddr", true);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new BgpPipelineFactory(bgpController, true);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(getBgpPortNum());
cg = new DefaultChannelGroup();
serverChannel = bootstrap.bind(sa);
cg.add(serverChannel);
log.info("Listening for Peer connection on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: startServer
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
private void startServer() {
ChannelFactory channelFactory = new NioServerSocketChannelFactory(
newCachedThreadPool(groupedThreads("onos/fpm", "sm-boss-%d")),
newCachedThreadPool(groupedThreads("onos/fpm", "sm-worker-%d")));
ChannelPipelineFactory pipelineFactory = () -> {
// Allocate a new session per connection
FpmSessionHandler fpmSessionHandler =
new FpmSessionHandler(new InternalFpmListener());
FpmFrameDecoder fpmFrameDecoder =
new FpmFrameDecoder();
// Setup the processing pipeline
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("FpmFrameDecoder", fpmFrameDecoder);
pipeline.addLast("FpmSession", fpmSessionHandler);
return pipeline;
};
InetSocketAddress listenAddress = new InetSocketAddress(FPM_PORT);
serverBootstrap = new ServerBootstrap(channelFactory);
serverBootstrap.setOption("child.reuseAddr", true);
serverBootstrap.setOption("child.keepAlive", true);
serverBootstrap.setOption("child.tcpNoDelay", true);
serverBootstrap.setPipelineFactory(pipelineFactory);
try {
serverChannel = serverBootstrap.bind(listenAddress);
allChannels.add(serverChannel);
} catch (ChannelException e) {
log.debug("Exception binding to FPM port {}: ",
listenAddress.getPort(), e);
stopServer();
}
}
示例9: start
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start() {
log.debug("BGP Session Manager start.");
isShutdown = false;
ChannelFactory channelFactory = new NioServerSocketChannelFactory(
newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")),
newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d")));
ChannelPipelineFactory pipelineFactory = () -> {
// Allocate a new session per connection
BgpSession bgpSessionHandler =
new BgpSession(BgpSessionManager.this);
BgpFrameDecoder bgpFrameDecoder =
new BgpFrameDecoder(bgpSessionHandler);
// Setup the processing pipeline
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("BgpFrameDecoder", bgpFrameDecoder);
pipeline.addLast("BgpSession", bgpSessionHandler);
return pipeline;
};
InetSocketAddress listenAddress =
new InetSocketAddress(bgpPort);
serverBootstrap = new ServerBootstrap(channelFactory);
// serverBootstrap.setOptions("reuseAddr", true);
serverBootstrap.setOption("child.keepAlive", true);
serverBootstrap.setOption("child.tcpNoDelay", true);
serverBootstrap.setPipelineFactory(pipelineFactory);
try {
serverChannel = serverBootstrap.bind(listenAddress);
allChannels.add(serverChannel);
} catch (ChannelException e) {
log.debug("Exception binding to BGP port {}: ",
listenAddress.getPort(), e);
}
}
示例10: initHttpBootstrap
import org.jboss.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
private void initHttpBootstrap(int myport) {
logger.info("initHttpBootstrap...........");
final ServerConfig serverConfig = new ServerConfig(myport);
final ChannelGroup channelGroup = new DefaultChannelGroup(getClass().getName());
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
//建議用ThreadPoolExecutor代替
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool(), serverConfig.getThreadCnt()));
//設置常見參數
bootstrap.setOption("tcpNoDelay","true");//禁用nagle算法
bootstrap.setOption("reuseAddress", "true");
bootstrap.setOption("SO_RCVBUF",1024*128);
bootstrap.setOption("SO_SNDBUF",1024*128);
timer = new HashedWheelTimer();
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
int readTimeout = serverConfig.getReadTimeout();
if (readTimeout > 0) {
pipeline.addLast("timeout", new ReadTimeoutHandler(timer, readTimeout, TimeUnit.MILLISECONDS));
}
pipeline.addLast("decoder", new RpcRequestDecode());
pipeline.addLast("encoder", new RpcResponseEncode());
pipeline.addLast("handler", new NettyRpcServerHandler(channelGroup));
return pipeline;
}
});
int port = serverConfig.getPort();
if (!checkPortConfig(port)) {
throw new IllegalStateException("port: " + port + " already in use!");
}
Channel channel = bootstrap.bind(new InetSocketAddress(port));
channelGroup.add(channel);
logger.info("voyage server started");
waitForShutdownCommand();
ChannelGroupFuture future = channelGroup.close();
future.awaitUninterruptibly();
bootstrap.releaseExternalResources();
timer.stop();
timer = null;
logger.info("voyage server stoped");
}