use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project opennms by OpenNMS.
the class TcpOutputStrategyTest method setUpClass.
@BeforeClass
public static void setUpClass() {
// Setup a quick Netty TCP server that decodes the protobuf messages
// and appends these to a list when received
ChannelFactory factory = new NioServerSocketChannelFactory();
ServerBootstrap bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
return Channels.pipeline(new ProtobufDecoder(PerformanceDataReadings.getDefaultInstance()), new PerfDataServerHandler());
}
});
Channel channel = bootstrap.bind(new InetSocketAddress(0));
InetSocketAddress addr = (InetSocketAddress) channel.getLocalAddress();
// Point the TCP exporter to our server
System.setProperty("org.opennms.rrd.tcp.host", addr.getHostString());
System.setProperty("org.opennms.rrd.tcp.port", Integer.toString(addr.getPort()));
// Always use queueing during these tests
System.setProperty("org.opennms.rrd.usequeue", Boolean.TRUE.toString());
// Use the temporary folder as the base directory
System.setProperty("rrd.base.dir", tempFolder.getRoot().getAbsolutePath());
}
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 voldemort by voldemort.
the class AbstractRestService method startInner.
@Override
protected void startInner() {
initialize();
// Configure the service
this.workerPool = (ThreadPoolExecutor) Executors.newCachedThreadPool();
this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), workerPool));
this.bootstrap.setOption("backlog", this.coordinatorConfig.getNettyServerBacklog());
this.bootstrap.setOption("child.tcpNoDelay", true);
this.bootstrap.setOption("child.keepAlive", true);
this.bootstrap.setOption("child.reuseAddress", true);
// Set up the event pipeline factory.
this.bootstrap.setPipelineFactory(getPipelineFactory());
// Assuming JMX is always enabled for service
JmxUtils.registerMbean(this, JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()), JmxUtils.getClassName(this.getClass())));
// Register MBeans for connection stats
JmxUtils.registerMbean(this.connectionStats, JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()), JmxUtils.getClassName(this.connectionStats.getClass())));
// Bind and start to accept incoming connections.
this.channel = this.bootstrap.bind(new InetSocketAddress(getServicePort()));
logger.info(getServiceName() + " service started on port " + getServicePort());
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project voldemort by voldemort.
the class RestService method startInner.
@Override
protected void startInner() {
// Configure the server.
this.workerPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(config.getNumRestServiceNettyWorkerThreads());
this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newFixedThreadPool(config.getNumRestServiceNettyBossThreads()), workerPool));
this.bootstrap.setOption("backlog", config.getRestServiceNettyServerBacklog());
this.bootstrap.setOption("child.tcpNoDelay", true);
this.bootstrap.setOption("child.keepAlive", true);
this.bootstrap.setOption("child.reuseAddress", true);
this.bootstrap.setPipelineFactory(new RestPipelineFactory(storeRepository, config, localZoneId, storeDefinitions, allChannels));
// Bind and start to accept incoming connections.
this.nettyServerChannel = this.bootstrap.bind(new InetSocketAddress(this.port));
allChannels.add(nettyServerChannel);
logger.info("REST service started on port " + this.port);
// Register MBeans for Netty worker pool stats
if (config.isJmxEnabled()) {
JmxUtils.registerMbean(this, JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()), JmxUtils.getClassName(this.getClass())));
}
}
use of org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory in project cdap by caskdata.
the class NettyRouter method bootstrapServer.
private void bootstrapServer(final ChannelUpstreamHandler connectionTracker) throws ServiceBindException {
ExecutorService serverBossExecutor = createExecutorService(serverBossThreadPoolSize, "router-server-boss-thread-%d");
ExecutorService serverWorkerExecutor = createExecutorService(serverWorkerThreadPoolSize, "router-server-worker-thread-%d");
serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(serverBossExecutor, serverWorkerExecutor));
serverBootstrap.setOption("backlog", serverConnectionBacklog);
serverBootstrap.setOption("child.bufferFactory", new DirectChannelBufferFactory());
// Setup the pipeline factory
serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (isSSLEnabled()) {
// Add SSLHandler is SSL is enabled
pipeline.addLast("ssl", sslHandlerFactory.create());
}
pipeline.addLast("tracker", connectionTracker);
pipeline.addLast("http-response-encoder", new HttpResponseEncoder());
pipeline.addLast("http-decoder", new HttpRequestDecoder());
pipeline.addLast("http-status-request-handler", new HttpStatusRequestHandler());
if (securityEnabled) {
pipeline.addLast("access-token-authenticator", new SecurityAuthenticationHttpHandler(realm, tokenValidator, configuration, accessTokenTransformer, discoveryServiceClient));
}
// for now there's only one hardcoded rule, but if there will be more, we may want it generic and configurable
pipeline.addLast("http-request-handler", new HttpRequestHandler(clientBootstrap, serviceLookup, ImmutableList.<ProxyRule>of()));
return pipeline;
}
});
// Start listening on ports.
ImmutableMap.Builder<Integer, String> serviceMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, Integer> forward : serviceToPortMap.entrySet()) {
int port = forward.getValue();
String service = forward.getKey();
String boundService = serviceLookup.getService(port);
if (boundService != null) {
LOG.warn("Port {} is already configured to service {}, ignoring forward for service {}", port, boundService, service);
continue;
}
InetSocketAddress bindAddress = new InetSocketAddress(hostname, port);
LOG.info("Starting Netty Router for service {} on address {}...", service, bindAddress);
try {
Channel channel = serverBootstrap.bind(bindAddress);
InetSocketAddress boundAddress = (InetSocketAddress) channel.getLocalAddress();
serviceMapBuilder.put(boundAddress.getPort(), service);
channelGroup.add(channel);
// Update service map
serviceLookup.updateServiceMap(serviceMapBuilder.build());
LOG.info("Started Netty Router for service {} on address {}.", service, boundAddress);
} catch (ChannelException e) {
if ((Throwables.getRootCause(e) instanceof BindException)) {
throw new ServiceBindException("Router", hostname.getCanonicalHostName(), port, e);
}
throw e;
}
}
}
Aggregations