use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project canal by alibaba.
the class CanalAdminWithNetty method start.
public void start() {
super.start();
this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
/*
* enable keep-alive mechanism, handle abnormal network connection
* scenarios on OS level. the threshold parameters are depended on OS.
* e.g. On Linux: net.ipv4.tcp_keepalive_time = 300
* net.ipv4.tcp_keepalive_probes = 2 net.ipv4.tcp_keepalive_intvl = 30
*/
bootstrap.setOption("child.keepAlive", true);
/*
* optional parameter.
*/
bootstrap.setOption("child.tcpNoDelay", true);
// 构造对应的pipeline
bootstrap.setPipelineFactory(() -> {
ChannelPipeline pipelines = Channels.pipeline();
pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
// support to maintain child socket channel.
pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler(childGroups));
pipelines.addLast(ClientAuthenticationHandler.class.getName(), new ClientAuthenticationHandler(canalAdmin));
SessionHandler sessionHandler = new SessionHandler(canalAdmin);
pipelines.addLast(SessionHandler.class.getName(), sessionHandler);
return pipelines;
});
// 启动
if (StringUtils.isNotEmpty(ip)) {
this.serverChannel = bootstrap.bind(new InetSocketAddress(this.ip, this.port));
} else {
this.serverChannel = bootstrap.bind(new InetSocketAddress(this.port));
}
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project http-client by biasedbit.
the class DummyHttpServer method init.
// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
Executor bossExecutor = Executors.newCachedThreadPool();
Executor workerExecutor = Executors.newCachedThreadPool();
ChannelFactory factory;
if (useOldIo)
factory = new OioServerSocketChannelFactory(bossExecutor, workerExecutor);
else
factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
bootstrap = new ServerBootstrap(factory);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (useSsl) {
SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
engine.setUseClientMode(false);
pipeline.addLast("ssl", new SslHandler(engine));
}
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("decoder", new HttpRequestDecoder());
if (compressionLevel > 0)
pipeline.addLast("compressor", new HttpContentCompressor(compressionLevel));
// 5MB
pipeline.addLast("aggregator", new HttpChunkAggregator(5242880));
pipeline.addLast("handler", new RequestHandler());
return pipeline;
}
});
channelGroup = new DefaultChannelGroup("hotpotato-dummy-server-" + Integer.toHexString(hashCode()));
SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
Channel serverChannel = bootstrap.bind(bindAddress);
channelGroup.add(serverChannel);
return (running = serverChannel.isBound());
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project http-client by biasedbit.
the class UploadMirrorHttpServer method init.
// interface ------------------------------------------------------------------------------------------------------
public boolean init() {
Executor bossExecutor = Executors.newCachedThreadPool();
Executor workerExecutor = Executors.newCachedThreadPool();
ChannelFactory factory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor);
bootstrap = new ServerBootstrap(factory);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (useSsl) {
SSLEngine engine = BogusSslContextFactory.getInstance().getServerContext().createSSLEngine();
engine.setUseClientMode(false);
pipeline.addLast("ssl", new SslHandler(engine));
}
pipeline.addLast("codec", new HttpServerCodec());
pipeline.addLast("handler", new RequestHandler());
return pipeline;
}
});
channelGroup = new DefaultChannelGroup("hotpotato-upload-server-" + Integer.toHexString(hashCode()));
SocketAddress bindAddress = (host != null) ? new InetSocketAddress(host, port) : new InetSocketAddress(port);
Channel serverChannel = bootstrap.bind(bindAddress);
channelGroup.add(serverChannel);
return (running = serverChannel.isBound());
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project pinpoint by naver.
the class PinpointServerAcceptor method createBootStrap.
private ServerBootstrap createBootStrap(int bossCount, int workerCount) {
// profiler, collector
ExecutorService boss = Executors.newCachedThreadPool(new PinpointThreadFactory("Pinpoint-Server-Boss", true));
NioServerBossPool nioServerBossPool = new NioServerBossPool(boss, bossCount, ThreadNameDeterminer.CURRENT);
ExecutorService worker = Executors.newCachedThreadPool(new PinpointThreadFactory("Pinpoint-Server-Worker", true));
NioWorkerPool nioWorkerPool = new NioWorkerPool(worker, workerCount, ThreadNameDeterminer.CURRENT);
NioServerSocketChannelFactory nioClientSocketChannelFactory = new NioServerSocketChannelFactory(nioServerBossPool, nioWorkerPool);
return new ServerBootstrap(nioClientSocketChannelFactory);
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project NabAlive by jcheype.
the class NabaliveServer method start.
@PostConstruct
public void start() {
logger.info("Starting server.");
// Configure the server.
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
// Set up the pipeline factory.
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast("timeout", new IdleStateHandler(timer, 0, 0, 20));
pipeline.addLast("nabaliveServerHandler", nabaliveServerHandler);
return pipeline;
}
});
bootstrap.setOption("reuseAddress", true);
// Bind and start to accept incoming connections.
bind = bootstrap.bind(new InetSocketAddress(XMPP_PORT));
}
Aggregations