Java Code Examples for org.jboss.netty.bootstrap.ServerBootstrap#bind()

The following examples show how to use org.jboss.netty.bootstrap.ServerBootstrap#bind() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: ShuffleHandler.java    From hadoop 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);
  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(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 7
Source File: NettyRev.java    From jlogstash-input-plugin with Apache License 2.0 5 votes vote down vote up
public void startup(){
        try {
            bossExecutor = Executors.newCachedThreadPool();
            workerExecutor = Executors.newCachedThreadPool();
            bootstrap = new ServerBootstrap(
                    new NioServerSocketChannelFactory(
                            bossExecutor,workerExecutor));
            final NettyServerHandler nettyServerHandler = new NettyServerHandler();
            // 设置一个处理客户端消息和各种消息事件的类(Handler)
            bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
                @Override
                public ChannelPipeline getPipeline() throws Exception {
                    ChannelPipeline pipeline = Channels.pipeline();
                    pipeline.addLast(
                            "decoder",
                            new DelimiterBasedFrameDecoder(Integer.MAX_VALUE,
                                    false, true, ChannelBuffers.copiedBuffer(
                                    delimiter,
                                    Charset.forName(encoding))));
                    pipeline.addLast("handler", nettyServerHandler);
                    return pipeline;
                }
            });
            bootstrap.setOption("child.receiveBufferSize", receiveBufferSize);
            bootstrap.setOption("child.keepAlive", true);
//            bootstrap.setOption("child.tcpNoDelay", true);
            bootstrap.bind(new InetSocketAddress(InetAddress.getByName(host),
                    port));
            logger.warn("netty server start up success port:{}.", port);
        } catch (Exception e) {
            logger.error(e.getMessage());
            System.exit(1);
        }
    }
 
Example 8
Source File: NettyServer.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setPipelineFactory(() -> {
        NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec() ,getUrl(), NettyServer.this);
        ChannelPipeline pipeline = Channels.pipeline();
        /*int idleTimeout = getIdleTimeout();
        if (idleTimeout > 10000) {
            pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
        }*/
        pipeline.addLast("decoder", adapter.getDecoder());
        pipeline.addLast("encoder", adapter.getEncoder());
        pipeline.addLast("handler", nettyHandler);
        return pipeline;
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
 
Example 9
Source File: Netty.java    From jlogstash-input-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void emit() {
	// TODO Auto-generated method stub
	// Server服务启动器
	try {
		 bossExecutor = Executors.newCachedThreadPool();
		 workerExecutor = Executors.newCachedThreadPool();
		 bootstrap = new ServerBootstrap(
				new NioServerSocketChannelFactory(
						bossExecutor,workerExecutor));
		final NettyServerHandler nettyServerHandler = new NettyServerHandler(
				this);
		// 设置一个处理客户端消息和各种消息事件的类(Handler)
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			@Override
			public ChannelPipeline getPipeline() throws Exception {
				ChannelPipeline pipeline = Channels.pipeline();
				if(isExtract){
					pipeline.addLast("zlibDecoder", new ZlibDecoder(ZlibWrapper.GZIP));
				}
				pipeline.addLast(
						"decoder",
						new DelimiterBasedFrameDecoder(Integer.MAX_VALUE,
								false, true, ChannelBuffers.copiedBuffer(
										delimiter,
										Charset.forName(encoding))));
				pipeline.addLast("handler", nettyServerHandler);
				return pipeline;
			}
		});
		bootstrap.setOption("child.receiveBufferSize", receiveBufferSize); 
		bootstrap.setOption("child.keepAlive", true);
		bootstrap.setOption("child.tcpNoDelay", true);
		bootstrap.bind(new InetSocketAddress(InetAddress.getByName(host),
				port));
	} catch (Exception e) {
		logger.error(e.getMessage());
		System.exit(1);
	}
}
 
Example 10
Source File: MemCacheDaemon.java    From fqueue with Apache License 2.0 5 votes vote down vote up
/**
 * Bind the network connection and start the network processing threads.
 */
public void start() {
	// TODO provide tweakable options here for passing in custom executors.
	channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors
			.newCachedThreadPool());

	allChannels = new DefaultChannelGroup("jmemcachedChannelGroup");

	ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);

	ChannelPipelineFactory pipelineFactory;
	if (binary)
		pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, verbose, idleTime,
				allChannels);
	else
		pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, verbose, idleTime, frameSize,
				allChannels);

	bootstrap.setOption("child.tcpNoDelay", true);
	bootstrap.setOption("child.keepAlive", true);
	bootstrap.setOption("child.receiveBufferSize", 1024 * 64);
	bootstrap.setPipelineFactory(pipelineFactory);

	Channel serverChannel = bootstrap.bind(addr);
	allChannels.add(serverChannel);

	log.info("Listening on " + String.valueOf(addr.getHostName()) + ":" + addr.getPort());

	running = true;
}
 
Example 11
Source File: BgpSessionManager.java    From onos with Apache License 2.0 5 votes vote down vote up
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 12
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 13
Source File: NettyServer.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec() ,getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();
            /*int idleTimeout = getIdleTimeout();
            if (idleTimeout > 10000) {
                pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
            }*/
            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: NetworkFailuresProxy.java    From flink with Apache License 2.0 5 votes vote down vote up
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 15
Source File: NettyServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec() ,getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();
            /*int idleTimeout = getIdleTimeout();
            if (idleTimeout > 10000) {
                pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
            }*/
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
 
Example 16
Source File: MongoServer.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.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 17
Source File: RpcServerBootstrap.java    From voyage with Apache License 2.0 4 votes vote down vote up
private void initHttpBootstrap(int myport) {
	logger.info("initHttpBootstrap...........");
	final ServerConfig serverConfig = new ServerConfig(myport);
	final ChannelGroup channelGroup = new DefaultChannelGroup(getClass().getName());
	bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
			//建议用ThreadPoolExecutor代替
			Executors.newCachedThreadPool(),
			Executors.newCachedThreadPool(), serverConfig.getThreadCnt()));
	//设置常见参数
	bootstrap.setOption("tcpNoDelay","true");//禁用nagle算法
	bootstrap.setOption("reuseAddress", "true");
	bootstrap.setOption("SO_RCVBUF",1024*128);
	bootstrap.setOption("SO_SNDBUF",1024*128);
	timer = new HashedWheelTimer();
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		public ChannelPipeline getPipeline() throws Exception {
			ChannelPipeline pipeline = Channels.pipeline();
			int readTimeout = serverConfig.getReadTimeout();
			if (readTimeout > 0) {
				pipeline.addLast("timeout", new ReadTimeoutHandler(timer, readTimeout, TimeUnit.MILLISECONDS));
			}
			pipeline.addLast("decoder", new RpcRequestDecode());
			pipeline.addLast("encoder", new RpcResponseEncode());
			pipeline.addLast("handler", new NettyRpcServerHandler(channelGroup));
			return pipeline;
		}
	});
	
	int port = serverConfig.getPort();
	if (!checkPortConfig(port)) {
		throw new IllegalStateException("port: " + port + " already in use!");
	}

	Channel channel = bootstrap.bind(new InetSocketAddress(port));
	channelGroup.add(channel);
	logger.info("voyage server started");

	waitForShutdownCommand();
	ChannelGroupFuture future = channelGroup.close();
	future.awaitUninterruptibly();
	bootstrap.releaseExternalResources();
	timer.stop();
	timer = null;

	logger.info("voyage server stoped");

}
 
Example 18
Source File: HttpServer.java    From glowroot with Apache License 2.0 4 votes vote down vote up
HttpServer(int port) throws InterruptedException {
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    bootstrap.setPipelineFactory(new HttpServerPipelineFactory());
    channel = bootstrap.bind(new InetSocketAddress(port));
}
 
Example 19
Source File: TajoPullServerService.java    From tajo with Apache License 2.0 4 votes vote down vote up
@Override
public void serviceInit(Configuration conf) throws Exception {
  tajoConf = new TajoConf(conf);

  manageOsCache = tajoConf.getBoolean(PullServerConstants.SHUFFLE_MANAGE_OS_CACHE,
      PullServerConstants.DEFAULT_SHUFFLE_MANAGE_OS_CACHE);

  readaheadLength = tajoConf.getInt(PullServerConstants.SHUFFLE_READAHEAD_BYTES,
      PullServerConstants.DEFAULT_SHUFFLE_READAHEAD_BYTES);

  int workerNum = tajoConf.getIntVar(ConfVars.SHUFFLE_RPC_SERVER_WORKER_THREAD_NUM);

  ThreadFactory bossFactory = new ThreadFactoryBuilder()
      .setNameFormat("TajoPullServerService Netty Boss #%d")
      .build();
  ThreadFactory workerFactory = new ThreadFactoryBuilder()
      .setNameFormat("TajoPullServerService Netty Worker #%d")
      .build();
  selector = new NioServerSocketChannelFactory(
      Executors.newCachedThreadPool(bossFactory),
      Executors.newCachedThreadPool(workerFactory),
      workerNum);

  localFS = new LocalFileSystem();

  maxUrlLength = tajoConf.getIntVar(ConfVars.PULLSERVER_FETCH_URL_MAX_LENGTH);

  LOG.info("Tajo PullServer initialized: readaheadLength=" + readaheadLength);

  ServerBootstrap bootstrap = new ServerBootstrap(selector);
  try {
    channelInitializer = new HttpChannelInitializer(tajoConf);
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
  bootstrap.setPipelineFactory(channelInitializer);

  port = tajoConf.getIntVar(ConfVars.PULLSERVER_PORT);
  Channel ch = bootstrap.bind(new InetSocketAddress(port));

  accepted.add(ch);
  port = ((InetSocketAddress)ch.getLocalAddress()).getPort();
  tajoConf.set(ConfVars.PULLSERVER_PORT.varname, Integer.toString(port));
  LOG.info(getName() + " listening on port " + port);

  sslFileBufferSize = tajoConf.getInt(PullServerConstants.SUFFLE_SSL_FILE_BUFFER_SIZE_KEY,
      PullServerConstants.DEFAULT_SUFFLE_SSL_FILE_BUFFER_SIZE);

  int cacheSize = tajoConf.getIntVar(ConfVars.PULLSERVER_CACHE_SIZE);
  int cacheTimeout = tajoConf.getIntVar(ConfVars.PULLSERVER_CACHE_TIMEOUT);

  indexReaderCache = CacheBuilder.newBuilder()
      .maximumSize(cacheSize)
      .expireAfterWrite(cacheTimeout, TimeUnit.MINUTES)
      .removalListener(removalListener)
      .build(
          new CacheLoader<IndexCacheKey, BSTIndexReader>() {
            @Override
            public BSTIndexReader load(IndexCacheKey key) throws Exception {
              return new BSTIndex(tajoConf).getIndexReader(new Path(key.getPath(), "index"));
            }
          }
      );
  lowCacheHitCheckThreshold = (int) (cacheSize * 0.1f);

  super.serviceInit(tajoConf);
  LOG.info("TajoPullServerService started: port=" + port);
}
 
Example 20
Source File: MockEndpoint.java    From zuul-netty with Apache License 2.0 4 votes vote down vote up
public void run() {
    // Configure the server.
    ServerBootstrap b = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

    b.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = pipeline();

            p.addLast("idle-detection", IDLE_STATE_HANDLER);
            p.addLast("http-decoder", new HttpRequestDecoder());
            p.addLast("http-encoder", new HttpResponseEncoder());
            p.addLast("keep-alive", KEEP_ALIVE_HANDLER);
            p.addLast("responder", new ChannelUpstreamHandler() {

                @Override
                public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
                    if (e instanceof MessageEvent) {
                        final MessageEvent me = (MessageEvent) e;
                        LOG.debug("received: {}", me.getMessage().getClass().getSimpleName());

                        Map<String, List<String>> params = new HashMap<>();

                        StringBuffer buf = new StringBuffer();
                        buf.setLength(0);
                        buf.append("HI");

                        if (me.getMessage() instanceof HttpRequest) {
                            final HttpRequest request = (HttpRequest) me.getMessage();

                            LOG.debug("request: {}", request);

                            QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
                            params = queryStringDecoder.getParameters();

                            if (!request.isChunked()) {
                                writeOutput(e.getChannel(), buf, params.containsKey("chunked"));
                            }
                        } else if (me.getMessage() instanceof HttpChunk) {
                            final HttpChunk chunk = (HttpChunk) me.getMessage();
                            if (chunk.isLast()) {
                                writeOutput(e.getChannel(), buf, params.containsKey("chunked"));
                            }
                        }
                    }
                }
            });

            return p;
        }

    });

    b.setOption("child.tcpNoDelay", true);
    //b.setOption("receiveBufferSizePredictorFactory", new AdaptiveReceiveBufferSizePredictorFactory(1024, 8192, 131072));
    b.bind(new InetSocketAddress(PORT));

    LOG.info("server bound to port {}", PORT);
}