public static ChannelFactory getChannelFactory(boolean nio) { if ( nio ) return new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); else return new OioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); }
@Override public void initialize(Map<String, String> configuration, GraylogServer graylogServer) throws MessageInputConfigurationException { socketAddress = new InetSocketAddress( configuration.get("listen_address"), Integer.parseInt(configuration.get("listen_port")) ); final ExecutorService bossThreadPool = Executors.newCachedThreadPool( new ThreadFactoryBuilder() .setNameFormat("input-relp-boss-%d") .build()); final ExecutorService workerThreadPool = Executors.newCachedThreadPool( new ThreadFactoryBuilder() .setNameFormat("input-relp-worker-%d") .build()); ServerBootstrap tcpBootstrap = new ServerBootstrap( new OioServerSocketChannelFactory(bossThreadPool, workerThreadPool) ); tcpBootstrap.setPipelineFactory(new RELPPipelineFactory(graylogServer)); try { tcpBootstrap.bind(socketAddress); } catch (ChannelException e) { LOG.error("Could not bind RELP input {}", socketAddress, e); } }
/** * Creates a new server instance on the specified port. * * @param port * The port */ public DefaultServer(final int port) { this.port = port; // Configure the server. bootstrap = new ServerBootstrap( new OioServerSocketChannelFactory( Executors.newCachedThreadPool(new DaemonThreadFactory()), Executors.newCachedThreadPool(new DaemonThreadFactory()))); // Set up the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline( new ObjectEncoder(ENCODER_ESTIMATED_LENGTH), // 1 MB default size new ObjectDecoder(DECODER_ESTIMATED_LENGTH, ClassResolvers.weakCachingResolver(null)), // 20 MB max. size - should be largely sufficient new ServerHandshakeHandler(channelContainer, HANDSHAKE_TIMEOUT_MILLIS), serverHandler); } }); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); }
@Override protected ServerSocketChannelFactory createSocketChannelFactory() { return new OioServerSocketChannelFactory(createBossExecutor(), createWorkerExecutor()); }