use of org.jboss.netty.bootstrap.ServerBootstrap in project graylog2-server by Graylog2.
the class NettyTransport method launch.
@Override
public void launch(final MessageInput input) throws MisfireException {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = getBaseChannelHandlers(input);
final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalHandlers = getFinalChannelHandlers(input);
handlerList.putAll(finalHandlers);
try {
bootstrap = getBootstrap();
bootstrap.setPipelineFactory(getPipelineFactory(handlerList));
// sigh, bindable bootstraps do not share a common interface
int receiveBufferSize;
if (bootstrap instanceof ConnectionlessBootstrap) {
acceptChannel = ((ConnectionlessBootstrap) bootstrap).bind(socketAddress);
final DefaultDatagramChannelConfig channelConfig = (DefaultDatagramChannelConfig) acceptChannel.getConfig();
receiveBufferSize = channelConfig.getReceiveBufferSize();
} else if (bootstrap instanceof ServerBootstrap) {
acceptChannel = ((ServerBootstrap) bootstrap).bind(socketAddress);
final ServerSocketChannelConfig channelConfig = (ServerSocketChannelConfig) acceptChannel.getConfig();
receiveBufferSize = channelConfig.getReceiveBufferSize();
} else {
log.error("Unknown Netty bootstrap class returned: {}. Cannot safely bind.", bootstrap);
throw new IllegalStateException("Unknown netty bootstrap class returned: " + bootstrap + ". Cannot safely bind.");
}
if (receiveBufferSize != getRecvBufferSize()) {
log.warn("receiveBufferSize (SO_RCVBUF) for input {} should be {} but is {}.", input, getRecvBufferSize(), receiveBufferSize);
}
} catch (Exception e) {
throw new MisfireException(e);
}
}
use of org.jboss.netty.bootstrap.ServerBootstrap 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.bootstrap.ServerBootstrap in project canal by alibaba.
the class CanalServerWithNetty method start.
public void start() {
super.start();
if (!embeddedServer.isStart()) {
embeddedServer.start();
}
this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
// 构造对应的pipeline
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipelines = Channels.pipeline();
pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler());
pipelines.addLast(ClientAuthenticationHandler.class.getName(), new ClientAuthenticationHandler(embeddedServer));
SessionHandler sessionHandler = new SessionHandler(embeddedServer);
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.bootstrap.ServerBootstrap 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.bootstrap.ServerBootstrap 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())));
}
}
Aggregations