Search in sources :

Example 1 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hadoop by apache.

the class Portmap method start.

void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress, final SocketAddress udpAddress) {
    tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    tcpServer.setPipelineFactory(new ChannelPipelineFactory() {

        private final HashedWheelTimer timer = new HashedWheelTimer();

        private final IdleStateHandler idleStateHandler = new IdleStateHandler(timer, 0, 0, idleTimeMilliSeconds, TimeUnit.MILLISECONDS);

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER, idleStateHandler, handler, RpcUtil.STAGE_RPC_TCP_RESPONSE);
        }
    });
    tcpServer.setOption("reuseAddress", true);
    tcpServer.setOption("child.reuseAddress", true);
    udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory(Executors.newCachedThreadPool()));
    udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE));
    udpServer.setOption("reuseAddress", true);
    tcpChannel = tcpServer.bind(tcpAddress);
    udpChannel = udpServer.bind(udpAddress);
    allChannels.add(tcpChannel);
    allChannels.add(udpChannel);
    LOG.info("Portmap server started at tcp://" + tcpChannel.getLocalAddress() + ", udp://" + udpChannel.getLocalAddress());
}
Also used : NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) IdleStateHandler(org.jboss.netty.handler.timeout.IdleStateHandler) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 2 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hadoop by apache.

the class ShuffleHandler method serviceStart.

// TODO change AbstractService to throw InterruptedException
@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.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));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) JobTokenSecretManager(org.apache.hadoop.mapreduce.security.token.JobTokenSecretManager) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteString(com.google.protobuf.ByteString) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TooLongFrameException(org.jboss.netty.handler.codec.frame.TooLongFrameException) FileNotFoundException(java.io.FileNotFoundException) DBException(org.iq80.leveldb.DBException)

Example 3 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hadoop by apache.

the class ShuffleHandler method serviceStop.

@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 (stateDb != null) {
        stateDb.close();
    }
    super.serviceStop();
}
Also used : ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 4 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hive by apache.

the class ShuffleHandler method stop.

protected void stop() throws Exception {
    accepted.close().awaitUninterruptibly(10, TimeUnit.SECONDS);
    if (selector != null) {
        ServerBootstrap bootstrap = new ServerBootstrap(selector);
        bootstrap.releaseExternalResources();
    }
    if (pipelineFact != null) {
        pipelineFact.destroy();
    }
    if (dirWatcher != null) {
        dirWatcher.stop();
    }
}
Also used : ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 5 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project crate by crate.

the class HttpTestServer method run.

public void run() {
    // Configure the server.
    ServerBootstrap bootstrap = new ServerBootstrap(this.channelFactory);
    // Set up the pipeline factory.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() throws Exception {
            // Create a default pipeline implementation.
            ChannelPipeline pipeline = Channels.pipeline();
            // Uncomment the following line if you want HTTPS
            //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
            //engine.setUseClientMode(false);
            //pipeline.addLast("ssl", new SslHandler(engine));
            pipeline.addLast("decoder", new HttpRequestDecoder());
            // Uncomment the following line if you don't want to handle HttpChunks.
            //pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            // Remove the following line if you don't want automatic content compression.
            pipeline.addLast("deflater", new HttpContentCompressor());
            pipeline.addLast("handler", new HttpTestServerHandler());
            return pipeline;
        }
    });
    // Bind and start to accept incoming connections.
    channel = bootstrap.bind(new InetSocketAddress(port));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Aggregations

ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)43 InetSocketAddress (java.net.InetSocketAddress)29 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)26 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)13 Channel (org.jboss.netty.channel.Channel)12 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)11 ChannelFactory (org.jboss.netty.channel.ChannelFactory)5 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)5 Test (org.junit.Test)5 HostnamePort (org.neo4j.helpers.HostnamePort)5 IOException (java.io.IOException)4 ExecutorService (java.util.concurrent.ExecutorService)4 ChannelException (org.jboss.netty.channel.ChannelException)4 Executor (java.util.concurrent.Executor)3 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)3 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)3 SocketAddress (java.net.SocketAddress)2 SSLEngine (javax.net.ssl.SSLEngine)2 ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)2 NioServerBossPool (org.jboss.netty.channel.socket.nio.NioServerBossPool)2