use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project weave by continuuity.
the class TrackerService method startUp.
@Override
protected void startUp() throws Exception {
Executor bossThreads = Executors.newFixedThreadPool(NUM_BOSS_THREADS, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("boss-thread").build());
Executor workerThreads = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("worker-thread#%d").build());
ChannelFactory factory = new NioServerSocketChannelFactory(bossThreads, workerThreads);
bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(MAX_INPUT_SIZE));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("compressor", new HttpContentCompressor());
pipeline.addLast("handler", new ReportHandler(resourceReport));
return pipeline;
}
});
Channel channel = bootstrap.bind(new InetSocketAddress(host, 0));
bindAddress = (InetSocketAddress) channel.getLocalAddress();
url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).resolve(TrackerService.PATH).toURL();
channelGroup.add(channel);
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project neo4j by neo4j.
the class NetworkReceiver method start.
@Override
public void start() throws Throwable {
channels = new DefaultChannelGroup();
// Listen for incoming connections
nioChannelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(daemon("Cluster boss", monitor)), Executors.newFixedThreadPool(2, daemon("Cluster worker", monitor)), 2);
serverBootstrap = new ServerBootstrap(nioChannelFactory);
serverBootstrap.setOption("child.tcpNoDelay", true);
serverBootstrap.setPipelineFactory(new NetworkNodePipelineFactory());
int[] ports = config.clusterServer().getPorts();
int minPort = ports[0];
int maxPort = ports.length == 2 ? ports[1] : minPort;
// Try all ports in the given range
port = listen(minPort, maxPort);
msgLog.debug("Started NetworkReceiver at " + config.clusterServer().getHost() + ":" + port);
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project neo4j by neo4j.
the class Server method start.
@Override
public void start() throws Throwable {
String className = getClass().getSimpleName();
ExecutorService bossExecutor = newCachedThreadPool(daemon("Boss-" + className));
ExecutorService workerExecutor = newCachedThreadPool(daemon("Worker-" + className));
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossExecutor, workerExecutor, config.getMaxConcurrentTransactions()));
bootstrap.setPipelineFactory(this);
PortRangeSocketBinder portRangeSocketBinder = new PortRangeSocketBinder(bootstrap);
try {
Connection connection = portRangeSocketBinder.bindToFirstAvailablePortInRange(config.getServerAddress());
Channel channel = connection.getChannel();
socketAddress = connection.getSocketAddress();
channelGroup = new DefaultChannelGroup();
channelGroup.add(channel);
msgLog.info(className + " communication server started and bound to " + socketAddress);
} catch (Exception ex) {
msgLog.error("Failed to bind server to " + socketAddress, ex);
bootstrap.releaseExternalResources();
targetCallExecutor.shutdownNow();
unfinishedTransactionExecutor.shutdownNow();
silentChannelExecutor.shutdownNow();
throw new IOException(ex);
}
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project graylog2-server by Graylog2.
the class AbstractTcpTransport method getBootstrap.
@Override
protected Bootstrap getBootstrap() {
final ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossExecutor, workerExecutor));
bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(8192));
bootstrap.setOption("receiveBufferSize", getRecvBufferSize());
bootstrap.setOption("child.receiveBufferSize", getRecvBufferSize());
bootstrap.setOption("child.keepAlive", tcpKeepalive);
return bootstrap;
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project JAirPort by froks.
the class RtspServer method run.
@Override
public void run() {
System.out.println("Listening on Port " + port);
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new RtspServerPipelineFactory());
bootstrap.bind(new InetSocketAddress(port));
while (!Thread.interrupted()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
}
System.out.println("RTSP-Server shutdown");
}
Aggregations