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 crate by crate.
the class PostgresNetty method doStart.
@Override
protected void doStart() {
if (!enabled) {
return;
}
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(daemonThreadFactory(settings, "postgres-netty-boss")), Executors.newCachedThreadPool(daemonThreadFactory(settings, "postgres-netty-worker"))));
bootstrap.setOption("child.tcpNoDelay", settings.getAsBoolean("tcp_no_delay", true));
bootstrap.setOption("child.keepAlive", settings.getAsBoolean("tcp_keep_alive", true));
bootstrap.setPipelineFactory(() -> {
ChannelPipeline pipeline = Channels.pipeline();
ConnectionContext connectionContext = new ConnectionContext(sqlOperations);
pipeline.addLast("frame-decoder", connectionContext.decoder);
pipeline.addLast("handler", connectionContext.handler);
return pipeline;
});
boolean success = false;
try {
boundAddress = resolveBindAddress();
namedLogger.info("{}", boundAddress);
success = true;
} finally {
if (!success) {
// stop boss/worker threads to avoid leaks
doStop();
}
}
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project socket.io-netty by ibdknox.
the class NSIOServer method start.
public void start() {
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
// Set up the event pipeline factory.
socketHandler = new WebSocketServerHandler(handler);
bootstrap.setPipelineFactory(new WebSocketServerPipelineFactory(socketHandler));
// Bind and start to accept incoming connections.
this.serverChannel = bootstrap.bind(new InetSocketAddress(port));
this.running = true;
try {
FlashPolicyServer.start();
} catch (Exception e) {
//TODO: this should not be exception
System.out.println("You must run as sudo for flash policy server. X-Domain flash will not currently work.");
}
System.out.println("Server Started at port [" + port + "]");
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project NabAlive by jcheype.
the class HttpServer method start.
public void start() {
//Timer timer = new HashedWheelTimer();
System.out.println("Runtime.getRuntime().availableProcessors(): " + Runtime.getRuntime().availableProcessors());
// ExecutorService bossExec = new OrderedMemoryAwareThreadPoolExecutor(2, 400000000, 2000000000, 60, TimeUnit.SECONDS);
// ExecutorService ioExec = new OrderedMemoryAwareThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1, 400000000, 2000000000, 60, TimeUnit.SECONDS);
//
// bootstrap = new ServerBootstrap(
// new NioServerSocketChannelFactory(bossExec, ioExec, Runtime.getRuntime().availableProcessors() + 1));
// Configure the server.
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("receiveBufferSize", 128 * 1024);
bootstrap.setOption("sendBufferSize", 128 * 1024);
bootstrap.setOption("reuseAddress", true);
bootstrap.setOption("backlog", 16384);
final HttpApiServerHandler httpApiServerHandler = new HttpApiServerHandler(restHandler);
// Set up the event pipeline factory.
bootstrap.setPipelineFactory(new HttpApiServerPipelineFactory(httpApiServerHandler));
// Bind and start to accept incoming connections.
Channel c = bootstrap.bind(new InetSocketAddress(port));
cg.add(c);
}
Aggregations