org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory Java Examples
The following examples show how to use
org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyConnector.java From netty-servlet with Apache License 2.0 | 6 votes |
@Override public NettyConnector start() throws Exception { bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Set up the event pipeline factory. bootstrap.setPipelineFactory(new HttpServerPipelineFactory(getDispatcher())); bootstrap.setOption("child.tcpNoDelay", true); // Bind and start to accept incoming connections. bootstrap.bind(new InetSocketAddress(getPort())); return this; }
Example #2
Source File: SyslogTcpSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Override public void start() { ChannelFactory factory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ServerBootstrap serverBootstrap = new ServerBootstrap(factory); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { syslogTcpHandler handler = new syslogTcpHandler(); handler.setEventSize(eventSize); handler.setFormater(formaterProp); return Channels.pipeline(handler); } }); logger.info("Syslog TCP Source starting..."); if (host == null) { nettyChannel = serverBootstrap.bind(new InetSocketAddress(port)); } else { nettyChannel = serverBootstrap.bind(new InetSocketAddress(host, port)); } super.start(); }
Example #3
Source File: TestDelegationTokenRemoteFetcher.java From big-c with Apache License 2.0 | 6 votes |
private ServerBootstrap startHttpServer(int port, final Token<DelegationTokenIdentifier> token, final URI url) { ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline(new HttpRequestDecoder(), new HttpChunkAggregator(65536), new HttpResponseEncoder(), new CredentialsLogicHandler(token, url.toString())); } }); bootstrap.bind(new InetSocketAddress("localhost", port)); return bootstrap; }
Example #4
Source File: ProgrammableTSOServer.java From phoenix-omid with Apache License 2.0 | 6 votes |
@Inject public ProgrammableTSOServer(int port) { // Setup netty listener factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setNameFormat("boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setNameFormat("worker-%d").build()), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2); // Create the global ChannelGroup channelGroup = new DefaultChannelGroup(ProgrammableTSOServer.class.getName()); ServerBootstrap bootstrap = new ServerBootstrap(factory); bootstrap.setPipelineFactory(new TSOChannelHandler.TSOPipelineFactory(this)); // Add the parent channel to the group Channel channel = bootstrap.bind(new InetSocketAddress(port)); channelGroup.add(channel); LOG.info("********** Dumb TSO Server running on port {} **********", port); }
Example #5
Source File: TSOChannelHandler.java From phoenix-omid with Apache License 2.0 | 6 votes |
@Inject public TSOChannelHandler(TSOServerConfig config, RequestProcessor requestProcessor, MetricsRegistry metrics) { this.config = config; this.metrics = metrics; this.requestProcessor = requestProcessor; // Setup netty listener this.factory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("worker-%d").build()), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2); this.bootstrap = new ServerBootstrap(factory); bootstrap.setPipelineFactory(new TSOPipelineFactory(this)); }
Example #6
Source File: TestDelegationTokenRemoteFetcher.java From hadoop with Apache License 2.0 | 6 votes |
private ServerBootstrap startHttpServer(int port, final Token<DelegationTokenIdentifier> token, final URI url) { ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline(new HttpRequestDecoder(), new HttpChunkAggregator(65536), new HttpResponseEncoder(), new CredentialsLogicHandler(token, url.toString())); } }); bootstrap.bind(new InetSocketAddress("localhost", port)); return bootstrap; }
Example #7
Source File: NettyServer.java From anima with GNU General Public License v3.0 | 6 votes |
@Override public void doOpen() throws Throwable { ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", false)); ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true)); int ioThread = conf.getInt(Constants.IO_THREADS,Constants.DEFAULT_IO_THREADS); ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, ioThread); bootstrap = new ServerBootstrap(channelFactory); final NettyHandler nettyHandler = new NettyHandler(getConf(), this); channels = nettyHandler.getChannels(); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(conf,getCodec(), NettyServer.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); // bind channel = bootstrap.bind(getBindAddress()); }
Example #8
Source File: NettyMapOutputHttpServer.java From RDFS with Apache License 2.0 | 6 votes |
public synchronized void init(Configuration conf) { ThreadFactory bossFactory = new ThreadFactoryBuilder() .setNameFormat("ShuffleHandler Netty Boss #%d") .build(); ThreadFactory workerFactory = new ThreadFactoryBuilder() .setNameFormat("ShuffleHandler Netty Worker #%d") .build(); int maximumPoolSize = conf.getInt(MAXIMUM_THREAD_POOL_SIZE, DEFAULT_MAXIMUM_THREAD_POOL_SIZE); try { workerThreadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(workerFactory); workerThreadPool.setMaximumPoolSize(maximumPoolSize); } catch (ClassCastException e) { LOG.warn("Netty worker thread pool is not of type ThreadPoolExecutor", e); } LOG.info("Netty starting up with a maximum of " + maximumPoolSize + " worker threads"); channelFactory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(bossFactory), workerThreadPool, maximumPoolSize); }
Example #9
Source File: NettyTest.java From java-codes with MIT License | 6 votes |
public static void main(String[] args) { // Server服务启动器 ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // 设置一个处理客户端消息和各种消息事件的类(Handler) bootstrap .setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { return Channels .pipeline(new HelloServerHandler()); } }); // 开放8000端口供客户端访问。 bootstrap.bind(new InetSocketAddress(8000)); }
Example #10
Source File: PullServerAuxService.java From incubator-tajo with Apache License 2.0 | 6 votes |
@Override public synchronized void init(Configuration conf) { try { manageOsCache = conf.getBoolean(SHUFFLE_MANAGE_OS_CACHE, DEFAULT_SHUFFLE_MANAGE_OS_CACHE); readaheadLength = conf.getInt(SHUFFLE_READAHEAD_BYTES, DEFAULT_SHUFFLE_READAHEAD_BYTES); ThreadFactory bossFactory = new ThreadFactoryBuilder() .setNameFormat("PullServerAuxService Netty Boss #%d") .build(); ThreadFactory workerFactory = new ThreadFactoryBuilder() .setNameFormat("PullServerAuxService Netty Worker #%d") .build(); selector = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(bossFactory), Executors.newCachedThreadPool(workerFactory)); localFS = new LocalFileSystem(); super.init(new Configuration(conf)); } catch (Throwable t) { LOG.error(t); } }
Example #11
Source File: HttpServer.java From feeyo-hlsserver with Apache License 2.0 | 6 votes |
public void startup(int port) { final int maxContentLength = 1024 * 1024 * 1024; bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(bossExecutor, workerExecutor)); bootstrap.setOption("connectTimeoutMillis", 10000); bootstrap.setOption("reuseAddress", true); // kernel optimization bootstrap.setOption("keepAlive", true); // for mobiles & our bootstrap.setOption("tcpNoDelay", true); // better latency over bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline p = Channels.pipeline(); p.addLast("http-encoder", new HttpResponseEncoder()); p.addLast("http-decoder", new HttpRequestDecoder()); p.addLast("http-aggregator", new HttpChunkAggregator( maxContentLength )); p.addLast("server-handler", new HttpServerRequestHandler()); return p; } }); channel = bootstrap.bind(new InetSocketAddress(port)); }
Example #12
Source File: NettyServer.java From DataLink with Apache License 2.0 | 6 votes |
public void startup() { this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // 构造对应的pipeline bootstrap.setPipelineFactory(() -> { ChannelPipeline pipelines = Channels.pipeline(); pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder()); SessionHandler sessionHandler = new SessionHandler(coordinator); pipelines.addLast(SessionHandler.class.getName(), sessionHandler); return pipelines; }); // 启动 if (StringUtils.isNotEmpty(hostname)) { this.serverChannel = bootstrap.bind(new InetSocketAddress(this.hostname, this.port)); } else { this.serverChannel = bootstrap.bind(new InetSocketAddress(this.port)); } logger.info(" ##Netty Server is started."); }
Example #13
Source File: ChannelImapResponseWriter.java From james-project with Apache License 2.0 | 6 votes |
@Override public void write(Literal literal) throws IOException { if (channel.isConnected()) { InputStream in = literal.getInputStream(); if (in instanceof FileInputStream && channel.getFactory() instanceof NioServerSocketChannelFactory) { FileChannel fc = ((FileInputStream) in).getChannel(); // Zero-copy is only possible if no SSL/TLS and no COMPRESS is in place // // See JAMES-1305 and JAMES-1306 ChannelPipeline cp = channel.getPipeline(); if (zeroCopy && cp.get(SslHandler.class) == null && cp.get(ZlibEncoder.class) == null) { channel.write(new DefaultFileRegion(fc, fc.position(), literal.size())); } else { channel.write(new ChunkedNioFile(fc, 8192)); } } else { channel.write(new ChunkedStream(literal.getInputStream())); } } }
Example #14
Source File: EventReviewServer.java From hadoop-arch-book with Apache License 2.0 | 5 votes |
public void startServer() throws Exception { eventProcessor = EventProcessor.initAndStartEventProcess(config, flumePorts, useCheckPut); handler = new EventServerHandler(); ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.receiveBufferSize", 1048576); bootstrap.setOption("child.sendBufferSize", 1048576); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { ChannelPipeline p = Channels.pipeline(); p.addLast("batch", handler); return p; } }); LOG.info("EventReviewServer: binding to :" + portNumber); channel = bootstrap.bind(new InetSocketAddress(portNumber)); LOG.info("EventReviewServer: bound to :" + portNumber + " " + channel.isBound() + " " + channel.getLocalAddress()); }
Example #15
Source File: NetworkFailuresProxy.java From flink with Apache License 2.0 | 5 votes |
public NetworkFailuresProxy(int localPort, String remoteHost, int remotePort) { // Configure the bootstrap. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(executor, executor)); // Set up the event pipeline factory. ClientSocketChannelFactory channelFactory = new NioClientSocketChannelFactory(executor, executor); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // synchronized for a race between blocking and creating new handlers synchronized (networkFailureHandlers) { NetworkFailureHandler failureHandler = new NetworkFailureHandler( blocked, networkFailureHandler -> networkFailureHandlers.remove(networkFailureHandler), channelFactory, remoteHost, remotePort); networkFailureHandlers.add(failureHandler); pipeline.addLast(NETWORK_FAILURE_HANDLER_NAME, failureHandler); } return pipeline; } }); channel = serverBootstrap.bind(new InetSocketAddress(localPort)); LOG.info("Proxying [*:{}] to [{}:{}]", getLocalPort(), remoteHost, remotePort); }
Example #16
Source File: HttpDataServer.java From incubator-tajo with Apache License 2.0 | 5 votes |
public HttpDataServer(final InetSocketAddress addr, final DataRetriever retriever) { this.addr = addr; this.factory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), Runtime.getRuntime().availableProcessors() * 2); // Configure the server. this.bootstrap = new ServerBootstrap(factory); // Set up the event pipeline factory. this.bootstrap.setPipelineFactory( new HttpDataServerPipelineFactory(retriever)); this.channelGroup = new DefaultChannelGroup(); }
Example #17
Source File: CarbonTextServer.java From kairos-carbon with Apache License 2.0 | 5 votes |
@Override public void start() throws KairosDBException { // Configure the server. m_serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Configure the pipeline factory. m_serverBootstrap.setPipelineFactory(this); m_serverBootstrap.setOption("child.tcpNoDelay", true); m_serverBootstrap.setOption("child.keepAlive", true); m_serverBootstrap.setOption("reuseAddress", true); // Bind and start to accept incoming connections. m_serverBootstrap.bind(new InetSocketAddress(m_address, m_port)); m_udpBootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory()); m_udpBootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(m_maxSize)); m_udpBootstrap.setPipelineFactory(this); m_udpBootstrap.bind(new InetSocketAddress(m_port)); }
Example #18
Source File: Main.java From vmstats with Apache License 2.0 | 5 votes |
public void run(Hashtable<String, String> appConfig) { ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setPipelineFactory(new FakeCarbonPipelineFactory(appConfig)); bootstrap.bind(new InetSocketAddress(port)); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("receiveBufferSize", 1048576); }
Example #19
Source File: CarbonPickleServer.java From kairos-carbon with Apache License 2.0 | 5 votes |
@Override public void start() throws KairosDBException { // Configure the server. m_serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // Configure the pipeline factory. m_serverBootstrap.setPipelineFactory(this); m_serverBootstrap.setOption("child.tcpNoDelay", true); m_serverBootstrap.setOption("child.keepAlive", true); m_serverBootstrap.setOption("reuseAddress", true); // Bind and start to accept incoming connections. m_serverBootstrap.bind(new InetSocketAddress(m_address, m_port)); m_udpBootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory()); m_udpBootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(m_maxSize)); m_udpBootstrap.setPipelineFactory(this); m_udpBootstrap.bind(new InetSocketAddress(m_port)); }
Example #20
Source File: PinpointServerAcceptor.java From pinpoint with Apache License 2.0 | 5 votes |
private ServerBootstrap createBootStrap(int bossCount, int workerCount) { // profiler, collector ExecutorService boss = Executors.newCachedThreadPool(new PinpointThreadFactory("Pinpoint-Server-Boss", true)); NioServerBossPool nioServerBossPool = new NioServerBossPool(boss, bossCount, ThreadNameDeterminer.CURRENT); ExecutorService worker = Executors.newCachedThreadPool(new PinpointThreadFactory("Pinpoint-Server-Worker", true)); NioWorkerPool nioWorkerPool = new NioWorkerPool(worker, workerCount, ThreadNameDeterminer.CURRENT); NioServerSocketChannelFactory nioClientSocketChannelFactory = new NioServerSocketChannelFactory(nioServerBossPool, nioWorkerPool); return new ServerBootstrap(nioClientSocketChannelFactory); }
Example #21
Source File: NettyServer.java From recipes-rss with Apache License 2.0 | 5 votes |
/** * Builds and starts netty */ public NettyServer build() { PipelineFactory factory = new PipelineFactory(handlers, encoder, decoder, numBossThreads); ThreadPoolExecutor bossPool = new ThreadPoolExecutor( numBossThreads, numBossThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DescriptiveThreadFactory("Boss-Thread")); ThreadPoolExecutor workerPool = new ThreadPoolExecutor( numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DescriptiveThreadFactory("Worker-Thread")); ChannelFactory nioServer = new NioServerSocketChannelFactory( bossPool, workerPool, numWorkerThreads); ServerBootstrap serverBootstrap = new ServerBootstrap(nioServer); serverBootstrap.setOption("reuseAddress", true); serverBootstrap.setOption("keepAlive", true); serverBootstrap.setPipelineFactory(factory); Channel serverChannel = serverBootstrap.bind(new InetSocketAddress( host, port)); logger.info("Started netty server {}:{}", host, port); NettyServer server = new NettyServer(); server.addChannel(serverChannel); return server; }
Example #22
Source File: AvroSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Override public void start() { logger.info("Starting {}...", this); Responder responder = new SpecificResponder(AvroSourceProtocol.class, this); NioServerSocketChannelFactory socketChannelFactory = initSocketChannelFactory(); ChannelPipelineFactory pipelineFactory = initChannelPipelineFactory(); server = new NettyServer(responder, new InetSocketAddress(bindAddress, port), socketChannelFactory, pipelineFactory, null); connectionCountUpdater = Executors.newSingleThreadScheduledExecutor(); server.start(); sourceCounter.start(); super.start(); final NettyServer srv = (NettyServer)server; connectionCountUpdater.scheduleWithFixedDelay(new Runnable(){ @Override public void run() { sourceCounter.setOpenConnectionCount( Long.valueOf(srv.getNumActiveConnections())); } }, 0, 60, TimeUnit.SECONDS); logger.info("Avro source {} started.", getName()); }
Example #23
Source File: TestAvroSink.java From mt-flume with Apache License 2.0 | 5 votes |
private Server createSslServer(AvroSourceProtocol protocol) throws IllegalAccessException, InstantiationException { Server server = new NettyServer(new SpecificResponder( AvroSourceProtocol.class, protocol), new InetSocketAddress(hostname, port), new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()), new SSLChannelPipelineFactory(), null); return server; }
Example #24
Source File: FpmManager.java From onos with Apache License 2.0 | 5 votes |
private void startServer() { HashedWheelTimer timer = new HashedWheelTimer( groupedThreads("onos/fpm", "fpm-timer-%d", log)); ChannelFactory channelFactory = new NioServerSocketChannelFactory( newCachedThreadPool(groupedThreads("onos/fpm", "sm-boss-%d", log)), newCachedThreadPool(groupedThreads("onos/fpm", "sm-worker-%d", log))); ChannelPipelineFactory pipelineFactory = () -> { // Allocate a new session per connection IdleStateHandler idleHandler = new IdleStateHandler(timer, IDLE_TIMEOUT_SECS, 0, 0); FpmSessionHandler fpmSessionHandler = new FpmSessionHandler(this, new InternalFpmListener()); FpmFrameDecoder fpmFrameDecoder = new FpmFrameDecoder(); // Setup the processing pipeline ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("FpmFrameDecoder", fpmFrameDecoder); pipeline.addLast("idle", idleHandler); pipeline.addLast("FpmSession", fpmSessionHandler); return pipeline; }; InetSocketAddress listenAddress = new InetSocketAddress(FPM_PORT); serverBootstrap = new ServerBootstrap(channelFactory); serverBootstrap.setOption("child.reuseAddr", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setPipelineFactory(pipelineFactory); try { serverChannel = serverBootstrap.bind(listenAddress); allChannels.add(serverChannel); } catch (ChannelException e) { log.debug("Exception binding to FPM port {}: ", listenAddress.getPort(), e); stopServer(); } }
Example #25
Source File: BgpSessionManager.java From onos with Apache License 2.0 | 5 votes |
public void start() { log.debug("BGP Session Manager start."); isShutdown = false; ChannelFactory channelFactory = new NioServerSocketChannelFactory( newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d", log)), newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d", log))); ChannelPipelineFactory pipelineFactory = () -> { // Allocate a new session per connection BgpSession bgpSessionHandler = new BgpSession(BgpSessionManager.this); BgpFrameDecoder bgpFrameDecoder = new BgpFrameDecoder(bgpSessionHandler); // Setup the processing pipeline ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("BgpFrameDecoder", bgpFrameDecoder); pipeline.addLast("BgpSession", bgpSessionHandler); return pipeline; }; InetSocketAddress listenAddress = new InetSocketAddress(bgpPort); serverBootstrap = new ServerBootstrap(channelFactory); // serverBootstrap.setOptions("reuseAddr", true); serverBootstrap.setOption("child.keepAlive", true); serverBootstrap.setOption("child.tcpNoDelay", true); serverBootstrap.setPipelineFactory(pipelineFactory); try { serverChannel = serverBootstrap.bind(listenAddress); allChannels.add(serverChannel); } catch (ChannelException e) { log.debug("Exception binding to BGP port {}: ", listenAddress.getPort(), e); } }
Example #26
Source File: ProxyServer.java From zuul-netty with Apache License 2.0 | 5 votes |
public FutureTask<ProxyServer> run() { FutureTask<ProxyServer> future = new FutureTask<>(new Callable<ProxyServer>() { @Override public ProxyServer call() throws Exception { // Configure the server. bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); FiltersChangeNotifier changeNotifier = filtersChangeNotifier != null ? filtersChangeNotifier : FiltersChangeNotifier.IGNORE; CommonHttpPipeline pipelineFactory = new CommonHttpPipeline(TIMER); changeNotifier.addFiltersListener(pipelineFactory); bootstrap.setPipelineFactory(pipelineFactory); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.connectTimeoutMillis", 2000); /*bootstrap.setOption("child.writeBufferHighWaterMark", true); bootstrap.setOption("child.writeBufferLowWaterMark", true); bootstrap.setOption("child.writeSpinCount", true);*/ bootstrap.setOption("child.receiveBufferSizePredictor", new AdaptiveReceiveBufferSizePredictor()); channel = bootstrap.bind(new InetSocketAddress(port)); LOG.info("server bound to port {}", port); LOG.info("current handlers registred {}", pipelineFactory.getPipeline().getNames()); return ProxyServer.this; } }); final Thread thread = new Thread(future, "Proxy Server"); thread.start(); return future; }
Example #27
Source File: HttpServer.java From zuul-netty with Apache License 2.0 | 5 votes |
public synchronized void run() { // Configure the server. ServerBootstrap b = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); b.setPipelineFactory(new CommonHttpPipeline(TIMER)); b.setOption("child.tcpNoDelay", true); channel = b.bind(new InetSocketAddress(port)); LOG.info("server bound to port {}", port); }
Example #28
Source File: WebSocketServer.java From usergrid with Apache License 2.0 | 5 votes |
public void startServer() { if ( ( properties != null ) && ( Boolean .parseBoolean( properties.getProperty( "usergrid.websocket.disable", "false" ) ) ) ) { logger.info( "Usergrid WebSocket Server Disabled" ); return; } logger.info( "Starting Usergrid WebSocket Server" ); if ( realm != null ) { securityManager = new DefaultSecurityManager( realm ); } ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool() ) ); // Set up the pipeline factory. ExecutionHandler executionHandler = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor( 16, 1048576, 1048576 ) ); // Set up the event pipeline factory. bootstrap.setPipelineFactory( new WebSocketServerPipelineFactory( emf, smf, management, securityManager, executionHandler, ssl ) ); // Bind and start to accept incoming connections. channel = bootstrap.bind( new InetSocketAddress( 8088 ) ); logger.info( "Usergrid WebSocket Server started..." ); }
Example #29
Source File: MongoServer.java From usergrid with Apache License 2.0 | 5 votes |
public void startServer() { if ( ( properties != null ) && ( Boolean .parseBoolean( properties.getProperty( "usergrid.mongo.disable", "false" ) ) ) ) { logger.info( "Usergrid Mongo Emulation Server Disabled" ); return; } logger.info( "Starting Usergrid Mongo Emulation Server" ); if ( realm != null ) { securityManager = new DefaultSecurityManager( realm ); } // Configure the server. ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool() ) ); bootstrap.setOption( "child.bufferFactory", HeapChannelBufferFactory.getInstance( ByteOrder.LITTLE_ENDIAN ) ); // Set up the pipeline factory. ExecutionHandler executionHandler = new ExecutionHandler( new OrderedMemoryAwareThreadPoolExecutor( 16, 1048576, 1048576 ) ); // TODO if config'ed for SSL, start the SslMSPF instead, change port as well? bootstrap.setPipelineFactory( new MongoServerPipelineFactory( emf, smf, management, securityManager, executionHandler ) ); // Bind and start to accept incoming connections. channel = bootstrap.bind( new InetSocketAddress( 27017 ) ); logger.info( "Usergrid Mongo API Emulation Server accepting connections..." ); }
Example #30
Source File: TimestampServer.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
public void startServer() { ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("TimestampServer-%d").setDaemon(true).build()); this.factory = new NioServerSocketChannelFactory(executor, executor); SpliceLogUtils.info(LOG, "Timestamp Server starting (binding to port %s)...", port); ServerBootstrap bootstrap = new ServerBootstrap(factory); // If we end up needing to use one of the memory aware executors, // do so with code like this (leave commented out for reference). // But for now we can use the 'lite' implementation. // // final ThreadPoolExecutor pipelineExecutor = new OrderedMemoryAwareThreadPoolExecutor( // 5 /* threads */, 1048576, 1073741824, // 100, TimeUnit.MILLISECONDS, // Default would have been 30 SECONDS // Executors.defaultThreadFactory()); // bootstrap.setPipelineFactory(new TimestampPipelineFactory(pipelineExecutor, handler)); bootstrap.setPipelineFactory(new TimestampPipelineFactoryLite(handler)); bootstrap.setOption("tcpNoDelay", true); // bootstrap.setOption("child.sendBufferSize", 1048576); // bootstrap.setOption("child.receiveBufferSize", 1048576); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setOption("child.reuseAddress", true); // bootstrap.setOption("child.connectTimeoutMillis", 120000); this.channel = bootstrap.bind(new InetSocketAddress(getPortNumber())); SpliceLogUtils.info(LOG, "Timestamp Server started."); }