org.jboss.netty.bootstrap.ServerBootstrap Java Examples

The following examples show how to use org.jboss.netty.bootstrap.ServerBootstrap. 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: TajoPullServerService.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void start() {
  Configuration conf = getConfig();
  ServerBootstrap bootstrap = new ServerBootstrap(selector);

  try {
    pipelineFact = new HttpPipelineFactory(conf);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  bootstrap.setPipelineFactory(pipelineFact);
  port = conf.getInt(ConfVars.PULLSERVER_PORT.varname,
      ConfVars.PULLSERVER_PORT.defaultIntVal);
  Channel ch = bootstrap.bind(new InetSocketAddress(port));
  accepted.add(ch);
  port = ((InetSocketAddress)ch.getLocalAddress()).getPort();
  conf.set(ConfVars.PULLSERVER_PORT.varname, Integer.toString(port));
  pipelineFact.PullServer.setPort(port);
  LOG.info(getName() + " listening on port " + port);
  super.start();

  sslFileBufferSize = conf.getInt(SUFFLE_SSL_FILE_BUFFER_SIZE_KEY,
                                  DEFAULT_SUFFLE_SSL_FILE_BUFFER_SIZE);
}
 
Example #2
Source File: TestDelegationTokenRemoteFetcher.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: NettyTest.java    From java-codes with MIT License 6 votes vote down vote up
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 #4
Source File: HttpServer.java    From feeyo-hlsserver with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: ShuffleHandler.java    From tez with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
  ServerBootstrap bootstrap = new ServerBootstrap(selector);
  try {
    pipelineFact = new HttpPipelineFactory(conf);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  bootstrap.setPipelineFactory(pipelineFact);
  port = conf.getInt(SHUFFLE_PORT_CONFIG_KEY, DEFAULT_SHUFFLE_PORT);
  Channel ch = bootstrap.bind(new InetSocketAddress(port));
  accepted.add(ch);
  port = ((InetSocketAddress)ch.getLocalAddress()).getPort();
  conf.set(SHUFFLE_PORT_CONFIG_KEY, Integer.toString(port));
  pipelineFact.SHUFFLE.setPort(port);
  LOG.info("TezShuffleHandler" + " listening on port " + port);
}
 
Example #6
Source File: NettyServer.java    From DataLink with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: ShuffleHandler.java    From tez with Apache License 2.0 6 votes vote down vote up
@Override
protected void serviceStop() throws Exception {
  accepted.close().awaitUninterruptibly(10, TimeUnit.SECONDS);
  if (selector != null) {
    ServerBootstrap bootstrap = new ServerBootstrap(selector);
    bootstrap.releaseExternalResources();
  }
  if (pipelineFact != null) {
    pipelineFact.destroy();
  }
  if (timer != null) {
    // Release this shared timer resource
    timer.stop();
  }
  if (stateDb != null) {
    stateDb.close();
  }
  super.serviceStop();
}
 
Example #8
Source File: NettyTcpServerTransport.java    From msgpack-rpc-java with Apache License 2.0 6 votes vote down vote up
NettyTcpServerTransport(TcpServerConfig config, Server server, NettyEventLoop loop) {
    if (server == null) {
        throw new IllegalArgumentException("Server must not be null");
    }

    Address address = config.getListenAddress();
    RpcMessageHandler handler = new RpcMessageHandler(server);
    handler.useThread(true);

    ServerBootstrap bootstrap = new ServerBootstrap(loop.getServerFactory());
    bootstrap.setPipelineFactory(new StreamPipelineFactory(loop.getMessagePack(), handler));
    final Map<String, Object> options = config.getOptions();
    setIfNotPresent(options, CHILD_TCP_NODELAY, Boolean.TRUE, bootstrap);
    setIfNotPresent(options, REUSE_ADDRESS, Boolean.TRUE, bootstrap);
    bootstrap.setOptions(options);
    this.listenChannel = bootstrap.bind(address.getSocketAddress());
}
 
Example #9
Source File: TSOChannelHandler.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: ProgrammableTSOServer.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: NettyMapOutputHttpServer.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public synchronized int start(ChannelPipelineFactory pipelineFactory) {
  ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
  bootstrap.setPipelineFactory(pipelineFactory);
  // Try to bind to a port.  If the port is 0, netty will select a port.
  int bindAttempt = 0;
  while (bindAttempt < DEFAULT_BIND_ATTEMPT_MAX) {
    try {
      InetSocketAddress address = new InetSocketAddress(port);
      Channel ch = bootstrap.bind(address);
      accepted.add(ch);
      port = ((InetSocketAddress) ch.getLocalAddress()).getPort();
      break;
    } catch (ChannelException e) {
      LOG.warn("start: Likely failed to bind on attempt " +
               bindAttempt + " to port " + port, e);
      // Only increment the port number when set by the user
      if (port != 0) {
        ++port;
      }
      ++bindAttempt;
    }
  }

  LOG.info(this.getClass() + " is listening on port " + port);
  return port;
}
 
Example #12
Source File: SyslogTcpSource.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: NettyServer.java    From anima with GNU General Public License v3.0 6 votes vote down vote up
@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 #14
Source File: Controller.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tell controller that we're ready to accept pcc connections.
 */
public void run() {
    try {
        final ServerBootstrap bootstrap = createServerBootStrap();

        bootstrap.setOption("reuseAddr", true);
        bootstrap.setOption("child.keepAlive", true);
        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);

        ChannelPipelineFactory pfact = new PcepPipelineFactory(this);

        bootstrap.setPipelineFactory(pfact);
        InetSocketAddress sa = new InetSocketAddress(pcepPort);
        cg = new DefaultChannelGroup();
        cg.add(bootstrap.bind(sa));
        log.debug("Listening for PCC connection on {}", sa);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example #15
Source File: PinpointServerAcceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public PinpointServerAcceptor(ServerOption serverOption, ChannelFilter channelConnectedFilter, PipelineFactory pipelineFactory) {
    ServerBootstrap bootstrap = createBootStrap(1, WORKER_COUNT);
    setOptions(bootstrap);
    this.bootstrap = bootstrap;

    this.serverOption = Assert.requireNonNull(serverOption, "serverOption");
    logger.info("serverOption : {}", serverOption);

    this.healthCheckTimer = TimerFactory.createHashedWheelTimer("PinpointServerSocket-HealthCheckTimer", 50, TimeUnit.MILLISECONDS, 512);
    this.healthCheckManager = new HealthCheckManager(healthCheckTimer, serverOption.getHealthCheckPacketWaitTimeMillis(), channelGroup);

    this.requestManagerTimer = TimerFactory.createHashedWheelTimer("PinpointServerSocket-RequestManager", 50, TimeUnit.MILLISECONDS, 512);

    this.channelConnectedFilter = Assert.requireNonNull(channelConnectedFilter, "channelConnectedFilter");

    this.pipelineFactory = Assert.requireNonNull(pipelineFactory, "pipelineFactory");
    addPipeline(bootstrap, pipelineFactory);
}
 
Example #16
Source File: TestDelegationTokenRemoteFetcher.java    From big-c with Apache License 2.0 6 votes vote down vote up
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 #17
Source File: PullServerAuxService.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void start() {
  Configuration conf = getConfig();
  ServerBootstrap bootstrap = new ServerBootstrap(selector);
  try {
    pipelineFact = new HttpPipelineFactory(conf);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  bootstrap.setPipelineFactory(pipelineFact);
  port = conf.getInt(ConfVars.PULLSERVER_PORT.varname,
      ConfVars.PULLSERVER_PORT.defaultIntVal);
  Channel ch = bootstrap.bind(new InetSocketAddress(port));
  accepted.add(ch);
  port = ((InetSocketAddress)ch.getLocalAddress()).getPort();
  conf.set(ConfVars.PULLSERVER_PORT.varname, Integer.toString(port));
  pipelineFact.PullServer.setPort(port);
  LOG.info(getName() + " listening on port " + port);
  super.start();

  sslFileBufferSize = conf.getInt(SUFFLE_SSL_FILE_BUFFER_SIZE_KEY,
                                  DEFAULT_SUFFLE_SSL_FILE_BUFFER_SIZE);
}
 
Example #18
Source File: AbstractAsyncServer.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void bind() throws Exception {
    if (started) {
        throw new IllegalStateException("Server running already");
    }

    if (addresses.isEmpty()) {
        throw new RuntimeException("Please specify at least on socketaddress to which the server should get bound!");
    }

    bootstrap = new ServerBootstrap(createSocketChannelFactory());
    ChannelPipelineFactory factory = createPipelineFactory(channels);
    
    // Configure the pipeline factory.
    bootstrap.setPipelineFactory(factory);
    configureBootstrap(bootstrap);

    for (InetSocketAddress address : addresses) {
        channels.add(bootstrap.bind(address));
    }
    started = true;

}
 
Example #19
Source File: TajoPullServerService.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
public void serviceStop() throws Exception {
  // TODO: check this wait
  accepted.close().awaitUninterruptibly(10, TimeUnit.SECONDS);
  if (selector != null) {
    ServerBootstrap bootstrap = new ServerBootstrap(selector);
    bootstrap.releaseExternalResources();
  }

  if (channelInitializer != null) {
    channelInitializer.destroy();
  }

  localFS.close();
  indexReaderCache.invalidateAll();

  super.serviceStop();
}
 
Example #20
Source File: NettyConnector.java    From netty-servlet with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: EchoServer.java    From simple-netty-source with Apache License 2.0 6 votes vote down vote up
public void run() throws Exception{
    // Configure the server.
    System.out.println("server start");
    ServerBootstrap bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));

    // Set up the pipeline factory.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new EchoServerHandler());
        }
    });

    // Bind and start to accept incoming connections.
    bootstrap.bind(new InetSocketAddress(9123));
}
 
Example #22
Source File: WebSocketServer.java    From usergrid with Apache License 2.0 5 votes vote down vote up
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 #23
Source File: CarbonPickleServer.java    From kairos-carbon with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: CarbonTextServer.java    From kairos-carbon with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: ShuffleHandler.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
protected void serviceStart() throws Exception {
  Configuration conf = getConfig();
  userRsrc = new ConcurrentHashMap<String,String>();
  secretManager = new JobTokenSecretManager();
  recoverState(conf);
  ServerBootstrap bootstrap = new ServerBootstrap(selector);
  // Timer is shared across entire factory and must be released separately
  timer = new HashedWheelTimer();
  try {
    pipelineFact = new HttpPipelineFactory(conf, timer);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  bootstrap.setOption("backlog", conf.getInt(SHUFFLE_LISTEN_QUEUE_SIZE,
      DEFAULT_SHUFFLE_LISTEN_QUEUE_SIZE));
  bootstrap.setOption("child.keepAlive", true);
  bootstrap.setPipelineFactory(pipelineFact);
  port = conf.getInt(SHUFFLE_PORT_CONFIG_KEY, DEFAULT_SHUFFLE_PORT);
  Channel ch = bootstrap.bind(new InetSocketAddress(port));
  accepted.add(ch);
  port = ((InetSocketAddress)ch.getLocalAddress()).getPort();
  conf.set(SHUFFLE_PORT_CONFIG_KEY, Integer.toString(port));
  pipelineFact.SHUFFLE.setPort(port);
  LOG.info(getName() + " listening on port " + port);
  super.serviceStart();

  sslFileBufferSize = conf.getInt(SUFFLE_SSL_FILE_BUFFER_SIZE_KEY,
                                  DEFAULT_SUFFLE_SSL_FILE_BUFFER_SIZE);
  connectionKeepAliveEnabled =
      conf.getBoolean(SHUFFLE_CONNECTION_KEEP_ALIVE_ENABLED,
        DEFAULT_SHUFFLE_CONNECTION_KEEP_ALIVE_ENABLED);
  connectionKeepAliveTimeOut =
      Math.max(1, conf.getInt(SHUFFLE_CONNECTION_KEEP_ALIVE_TIME_OUT,
        DEFAULT_SHUFFLE_CONNECTION_KEEP_ALIVE_TIME_OUT));
  mapOutputMetaInfoCacheSize =
      Math.max(1, conf.getInt(SHUFFLE_MAPOUTPUT_META_INFO_CACHE_SIZE,
        DEFAULT_SHUFFLE_MAPOUTPUT_META_INFO_CACHE_SIZE));
}
 
Example #26
Source File: EventReviewServer.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
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 #27
Source File: NettyServerBase.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public void init(ChannelPipelineFactory pipeline, int workerNum) {
  ChannelFactory factory = RpcChannelFactory.createServerChannelFactory(serviceName, workerNum);

  pipelineFactory = pipeline;
  bootstrap = new ServerBootstrap(factory);
  bootstrap.setPipelineFactory(pipelineFactory);
  // TODO - should be configurable
  bootstrap.setOption("reuseAddress", true);
  bootstrap.setOption("child.tcpNoDelay", true);
  bootstrap.setOption("child.keepAlive", true);
  bootstrap.setOption("child.connectTimeoutMillis", 10000);
  bootstrap.setOption("child.connectResponseTimeoutMillis", 10000);
  bootstrap.setOption("child.receiveBufferSize", 1048576 * 10);
}
 
Example #28
Source File: PullServerAuxService.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void stop() {
  try {
    accepted.close().awaitUninterruptibly(10, TimeUnit.SECONDS);
    ServerBootstrap bootstrap = new ServerBootstrap(selector);
    bootstrap.releaseExternalResources();
    pipelineFact.destroy();

    localFS.close();
  } catch (Throwable t) {
    LOG.error(t);
  } finally {
    super.stop();
  }
}
 
Example #29
Source File: NettyServer.java    From recipes-rss with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #30
Source File: PinpointServerAcceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void setOptions(ServerBootstrap bootstrap) {
    // is read/write timeout necessary? don't need it because of NIO?
    // write timeout should be set through additional interceptor. write
    // timeout exists.

    // tcp setting
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);
    // buffer setting
    bootstrap.setOption("child.sendBufferSize", 1024 * 64);
    bootstrap.setOption("child.receiveBufferSize", 1024 * 64);

    // bootstrap.setOption("child.soLinger", 0);
}