Java Code Examples for org.jboss.netty.channel.ChannelPipeline#addLast()

The following examples show how to use org.jboss.netty.channel.ChannelPipeline#addLast() . 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: NettyTransport.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline channelPipeline = Channels.pipeline();
    channelPipeline.addLast("openChannels", nettyTransport.serverOpenChannels);
    SizeHeaderFrameDecoder sizeHeader = new SizeHeaderFrameDecoder();
    if (nettyTransport.maxCumulationBufferCapacity != null) {
        if (nettyTransport.maxCumulationBufferCapacity.bytes() > Integer.MAX_VALUE) {
            sizeHeader.setMaxCumulationBufferCapacity(Integer.MAX_VALUE);
        } else {
            sizeHeader.setMaxCumulationBufferCapacity((int) nettyTransport.maxCumulationBufferCapacity.bytes());
        }
    }
    if (nettyTransport.maxCompositeBufferComponents != -1) {
        sizeHeader.setMaxCumulationBufferComponents(nettyTransport.maxCompositeBufferComponents);
    }
    channelPipeline.addLast("size", sizeHeader);
    channelPipeline.addLast("dispatcher", new MessageChannelHandler(nettyTransport, nettyTransport.logger, name));
    return channelPipeline;
}
 
Example 2
Source File: BgpControllerImplTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress)
     throws InterruptedException {

     ChannelFactory channelFactory =
         new NioClientSocketChannelFactory(
                 Executors.newCachedThreadPool(),
                 Executors.newCachedThreadPool());
     ChannelPipelineFactory pipelineFactory = () -> {
         ChannelPipeline pipeline = Channels.pipeline();
         pipeline.addLast("BgpPeerFrameDecoderTest",
                 peerFrameDecoder);
         pipeline.addLast("BgpPeerChannelHandlerTest",
                 peerChannelHandler);
         return pipeline;
     };

     peerBootstrap = new ClientBootstrap(channelFactory);
     peerBootstrap.setOption("child.keepAlive", true);
     peerBootstrap.setOption("child.tcpNoDelay", true);
     peerBootstrap.setPipelineFactory(pipelineFactory);
     Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel();
     return channel;
}
 
Example 3
Source File: RemoteSyncPipelineFactory.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    RemoteSyncChannelHandler channelHandler = 
            new RemoteSyncChannelHandler(syncManager);
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("frameDecoder",
                     new ThriftFrameDecoder(maxFrameSize));
    pipeline.addLast("frameEncoder",
                     new ThriftFrameEncoder());
    pipeline.addLast("timeout",
                     new RSHandshakeTimeoutHandler(channelHandler,
                                                   timer, 3));

    pipeline.addLast("handler", channelHandler);
    return pipeline;
}
 
Example 4
Source File: BootstrapPipelineFactory.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    BootstrapChannelHandler handler = 
            new BootstrapChannelHandler(bootstrap);
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("frameDecoder",
                     new ThriftFrameDecoder(maxFrameSize));
    pipeline.addLast("frameEncoder",
                     new ThriftFrameEncoder());
    pipeline.addLast("timeout",
                     new BootstrapTimeoutHandler(timer, 10));

    pipeline.addLast("handler", handler);

    return pipeline;
}
 
Example 5
Source File: HttpServerPipelineFactory.java    From restcommander with Apache License 2.0 6 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {

        Integer max = Integer.valueOf(Play.configuration.getProperty("play.netty.maxContentLength", "-1"));
           
        ChannelPipeline pipeline = pipeline();
        PlayHandler playHandler = new PlayHandler();
        
        pipeline.addLast("flashPolicy", new FlashPolicyHandler()); 
        pipeline.addLast("decoder", new HttpRequestDecoder());
        pipeline.addLast("aggregator", new StreamChunkAggregator(max));
        pipeline.addLast("encoder", new HttpResponseEncoder());
        pipeline.addLast("chunkedWriter", playHandler.chunkedWriteHandler);
        pipeline.addLast("handler", playHandler);

        return pipeline;
    }
 
Example 6
Source File: PcepPipelineFactory.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    PcepChannelHandler handler = new PcepChannelHandler(controller);

    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("pcepmessagedecoder", new PcepMessageDecoder());
    pipeline.addLast("pcepmessageencoder", new PcepMessageEncoder());
    pipeline.addLast("idle", idleHandler);
    pipeline.addLast("waittimeout", readTimeoutHandler);
    pipeline.addLast("handler", handler);
    return pipeline;
}
 
Example 7
Source File: StreamPipelineFactory.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline p = Channels.pipeline();
    p.addLast("msgpack-decode-stream", new MessagePackStreamDecoder(messagePack));
    p.addLast("msgpack-encode", new MessagePackEncoder(messagePack));
    p.addLast("message", new MessageHandler(handler));
    return p;
}
 
Example 8
Source File: ClientCodecPipelineFactory.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline newPipeline() {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("encoder", new PacketEncoder());
    pipeline.addLast("decoder", new PacketDecoder());
    
    return pipeline;
}
 
Example 9
Source File: FakeCarbonPipelineFactory.java    From vmstats with Apache License 2.0 5 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
    // this is pretty verbose from the netty examples
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());
    pipeline.addLast("handler", new FakeCarbonHandler(appConfig));
    return pipeline;
}
 
Example 10
Source File: UdpWorker.java    From parallec with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() {

    // cannot have the DelimiterBasedFrameDecoder! does not work with
    // UDP; make packet missing.
    ChannelPipeline pipeline = Channels.pipeline();
    // ORDER matters!!! put the channdler first
    pipeline.addLast("idleTimer", idleStateHandler);
    pipeline.addLast("idleHandler", myIdleHandler);
    pipeline.addLast("stringDecoder", UdpMeta.stringDecoder);
    pipeline.addLast("stringEncoder", UdpMeta.stringEncoder);
    pipeline.addLast("UDPUpstreamHandler", new UdpChannelHandler(
            udpWorker));
    return pipeline;
}
 
Example 11
Source File: MyChannelPipelineFactory.java    From whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
	ChannelPipeline pipeline = Channels.pipeline();

	pipeline.addLast("objectencoder", new ObjectEncoder());

	pipeline.addLast("objectdecoder", new ObjectDecoder(ClassResolvers
			.cacheDisabled(this.getClass().getClassLoader())));
	pipeline.addLast("serverhandler", new MyServerHandler());
	return pipeline;
}
 
Example 12
Source File: StormClientPipelineFactory.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();

    // Decoder
    pipeline.addLast("decoder", new MessageDecoder(false, conf));
    // Encoder
    pipeline.addLast("encoder", new MessageEncoder());
    // business logic.
    pipeline.addLast("handler", new StormClientHandler(client));

    return pipeline;
}
 
Example 13
Source File: TSOClientRaw.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
public TSOClientRaw(String host, int port) throws InterruptedException, ExecutionException {
    // Start client with Nb of active threads = 3 as maximum.
    ChannelFactory factory = new NioClientSocketChannelFactory(
            Executors.newCachedThreadPool(
                    new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()),
            Executors.newCachedThreadPool(
                    new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), 3);
    // Create the bootstrap
    ClientBootstrap bootstrap = new ClientBootstrap(factory);

    InetSocketAddress addr = new InetSocketAddress(host, port);

    ChannelPipeline pipeline = bootstrap.getPipeline();
    pipeline.addLast("lengthbaseddecoder",
            new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4));
    pipeline.addLast("lengthprepender", new LengthFieldPrepender(4));
    pipeline.addLast("protobufdecoder",
            new ProtobufDecoder(TSOProto.Response.getDefaultInstance()));
    pipeline.addLast("protobufencoder", new ProtobufEncoder());

    Handler handler = new Handler();
    pipeline.addLast("handler", handler);

    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", true);
    bootstrap.setOption("reuseAddress", true);
    bootstrap.setOption("connectTimeoutMillis", 100);

    ChannelFuture channelFuture = bootstrap.connect(addr).await();
    channel = channelFuture.getChannel();
}
 
Example 14
Source File: OspfPipelineFactory.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("encoder", new OspfMessageDecoder());
    pipeline.addLast("decoder", new OspfMessageEncoder());
    pipeline.addLast("handler", ospfChannelHandler);

    return pipeline;
}
 
Example 15
Source File: TimestampPipelineFactoryLite.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    SpliceLogUtils.debug(LOG, "Creating new channel pipeline...");
    ChannelPipeline pipeline = Channels.pipeline();
    ((TimestampServerHandler) tsHandler).initializeIfNeeded();
    pipeline.addLast("decoder", new FixedLengthFrameDecoder(TimestampServer.FIXED_MSG_RECEIVED_LENGTH));
    pipeline.addLast("handler", tsHandler);
    SpliceLogUtils.debug(LOG, "Done creating channel pipeline");
    return pipeline;
}
 
Example 16
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 17
Source File: LoginToClientPipeLineFactory.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Decoding process will include the following handlers: - framedecoder -
 * packetdecoder - handler Encoding process: - packetencoder Please note the
 * sequence of handlers
 */
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();

    pipeline.addLast("framedecoder", new PacketFrameDecoder());
    pipeline.addLast("packetdecoder", new LoginPacketDecoder());
    pipeline.addLast("packetencoder", new LoginPacketEncoder());
    pipeline.addLast("executor", executionHandler);
    pipeline.addLast("handler", new ClientChannelHandler(clientPacketHandler));

    return pipeline;
}
 
Example 18
Source File: TSOClient.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
private TSOClient(OmidClientConfiguration omidConf) throws IOException {

        // Start client with Nb of active threads = 3 as maximum.
        int tsoExecutorThreads = omidConf.getExecutorThreads();

        factory = new NioClientSocketChannelFactory(
                Executors.newCachedThreadPool(
                        new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()),
                Executors.newCachedThreadPool(
                        new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), tsoExecutorThreads);
        // Create the bootstrap
        bootstrap = new ClientBootstrap(factory);

        requestTimeoutInMs = omidConf.getRequestTimeoutInMs();
        requestMaxRetries = omidConf.getRequestMaxRetries();
        tsoReconnectionDelayInSecs = omidConf.getReconnectionDelayInSecs();

        LOG.info("Connecting to TSO...");
        HostAndPort hp;
        switch (omidConf.getConnectionType()) {
            case HA:
                zkClient = ZKUtils.initZKClient(omidConf.getConnectionString(),
                                                omidConf.getZkNamespace(),
                                                omidConf.getZkConnectionTimeoutInSecs());
                zkCurrentTsoPath = omidConf.getZkCurrentTsoPath();
                configureCurrentTSOServerZNodeCache(zkCurrentTsoPath);
                String tsoInfo = getCurrentTSOInfoFoundInZK(zkCurrentTsoPath);
                // TSO info includes the new TSO host:port address and epoch
                String[] currentTSOAndEpochArray = tsoInfo.split("#");
                hp = HostAndPort.fromString(currentTSOAndEpochArray[0]);
                setTSOAddress(hp.getHostText(), hp.getPort());
                epoch = Long.parseLong(currentTSOAndEpochArray[1]);
                LOG.info("\t* Current TSO host:port found in ZK: {} Epoch {}", hp, getEpoch());
                break;
            case DIRECT:
            default:
                hp = HostAndPort.fromString(omidConf.getConnectionString());
                setTSOAddress(hp.getHostText(), hp.getPort());
                LOG.info("\t* TSO host:port {} will be connected directly", hp);
                break;
        }

        fsmExecutor = Executors.newSingleThreadScheduledExecutor(
                new ThreadFactoryBuilder().setNameFormat("tsofsm-%d").build());
        fsm = new StateMachine.FsmImpl(fsmExecutor);
        fsm.setInitState(new DisconnectedState(fsm));

        ChannelPipeline pipeline = bootstrap.getPipeline();
        pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4));
        pipeline.addLast("lengthprepender", new LengthFieldPrepender(4));
        pipeline.addLast("protobufdecoder", new ProtobufDecoder(TSOProto.Response.getDefaultInstance()));
        pipeline.addLast("protobufencoder", new ProtobufEncoder());
        pipeline.addLast("handler", new Handler(fsm));

        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setOption("keepAlive", true);
        bootstrap.setOption("reuseAddress", true);
        bootstrap.setOption("connectTimeoutMillis", 100);
        lowLatency = false;



        conflictDetectionLevel = omidConf.getConflictAnalysisLevel();

    }
 
Example 19
Source File: ManageSieveServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(final ChannelGroup group) {

    return new ChannelPipelineFactory() {

        private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group);

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            Encryption secure = getEncryption();
            if (secure != null && !secure.isStartTLS()) {
                // We need to set clientMode to false.
                // See https://issues.apache.org/jira/browse/JAMES-1025
                SSLEngine engine = secure.getContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));

            }
            pipeline.addLast(GROUP_HANDLER, groupHandler);
            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(ManageSieveServer.this.connectionLimit));
            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(ManageSieveServer.this.connPerIP));
            // Add the text line decoder which limit the max line length,
            // don't strip the delimiter and use CRLF as delimiter
            // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
            pipeline.addLast(FRAMER, getFrameHandlerFactory().create(pipeline));
            pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());
            pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());

            ExecutionHandler ehandler = getExecutionHandler();
            if (ehandler  != null) {
                pipeline.addLast(EXECUTION_HANDLER, ehandler);

            }
            pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
            pipeline.addLast(CORE_HANDLER, createCoreHandler());
            pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
            return pipeline;
        }

    };
}
 
Example 20
Source File: IMAPServer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(final ChannelGroup group) {
    
    return new ChannelPipelineFactory() {
        
        private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group);
        private final HashedWheelTimer timer = new HashedWheelTimer();
        
        private final TimeUnit timeoutUnit = TimeUnit.SECONDS;

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast(GROUP_HANDLER, groupHandler);
            pipeline.addLast("idleHandler", new IdleStateHandler(timer, 0, 0, timeout, timeoutUnit));
            pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler());
            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(IMAPServer.this.connectionLimit));

            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(IMAPServer.this.connPerIP));

            // Add the text line decoder which limit the max line length,
            // don't strip the delimiter and use CRLF as delimiter
            // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
            pipeline.addLast(FRAMER, getFrameHandlerFactory().create(pipeline));
           
            Encryption secure = getEncryption();
            if (secure != null && !secure.isStartTLS()) {
                // We need to set clientMode to false.
                // See https://issues.apache.org/jira/browse/JAMES-1025
                SSLEngine engine = secure.getContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));

            }
            pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());

            pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());

            ExecutionHandler ehandler = getExecutionHandler();
            if (ehandler  != null) {
                pipeline.addLast(EXECUTION_HANDLER, ehandler);

            }
            pipeline.addLast(REQUEST_DECODER, new ImapRequestFrameDecoder(decoder, inMemorySizeLimit, literalSizeLimit));

            pipeline.addLast(CORE_HANDLER, createCoreHandler());
            return pipeline;
        }

    };
}