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

The following are Jave code examples for showing how to use addLast() of the org.jboss.netty.channel.ChannelPipeline class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Elasticsearch   File: NettyTransport.java   Source Code and License Vote up 6 votes
@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
Project: athena   File: BgpControllerImplTest.java   Source Code and License Vote up 6 votes
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
Project: traccar-service   File: MeitrackProtocol.java   Source Code and License Vote up 6 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new MeitrackFrameDecoder());
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
            pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
    server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
            pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 4
Project: traccar-service   File: CastelProtocol.java   Source Code and License Vote up 6 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
            pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);

    server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 5
Project: athena   File: BgpPipelineFactory.java   Source Code and License Vote up 6 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
    BgpChannelHandler handler = new BgpChannelHandler(bgpController);

    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder());
    pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder());
    pipeline.addLast("holdTime", readTimeoutHandler);
    if (isBgpServ) {
        pipeline.addLast("PassiveHandler", handler);
    } else {
        pipeline.addLast("ActiveHandler", handler);
    }

    return pipeline;
}
 
Example 6
Project: iTAP-controller   File: RPCPipelineFactory.java   Source Code and License Vote up 6 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
    RPCChannelHandler channelHandler = 
            new RPCChannelHandler(syncManager, rpcService);

    IdleStateHandler idleHandler = 
            new IdleStateHandler(timer, 5, 10, 0);
    ReadTimeoutHandler readTimeoutHandler = 
            new ReadTimeoutHandler(timer, 30);
    
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("idle", idleHandler);
    pipeline.addLast("timeout", readTimeoutHandler);
    pipeline.addLast("handshaketimeout",
                     new HandshakeTimeoutHandler(channelHandler, timer, 10));

    pipeline.addLast("frameDecoder",
                     new ThriftFrameDecoder(maxFrameSize));
    pipeline.addLast("frameEncoder",
                     new ThriftFrameEncoder());

    pipeline.addLast("handler", channelHandler);
    return pipeline;
}
 
Example 7
Project: iTAP-controller   File: BootstrapPipelineFactory.java   Source Code and License Vote up 6 votes
@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 8
Project: athena   File: IsisPipelineFactory.java   Source Code and License Vote up 5 votes
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("encoder", new IsisMessageDecoder());
    pipeline.addLast("decoder", new IsisMessageEncoder());
    pipeline.addLast("handler", isisChannelHandler);

    return pipeline;
}
 
Example 9
Project: https-github.com-apache-zookeeper   File: NettyServerCnxnFactory.java   Source Code and License Vote up 5 votes
private synchronized void initSSL(ChannelPipeline p)
        throws X509Exception, KeyManagementException, NoSuchAlgorithmException {
    String authProviderProp = System.getProperty(ZKConfig.SSL_AUTHPROVIDER);
    SSLContext sslContext;
    if (authProviderProp == null) {
        sslContext = X509Util.createSSLContext();
    } else {
        sslContext = SSLContext.getInstance("TLSv1");
        X509AuthenticationProvider authProvider =
                (X509AuthenticationProvider)ProviderRegistry.getProvider(
                        System.getProperty(ZKConfig.SSL_AUTHPROVIDER,
                                "x509"));

        if (authProvider == null)
        {
            LOG.error("Auth provider not found: {}", authProviderProp);
            throw new SSLContextException(
                    "Could not create SSLContext with specified auth provider: " +
                    authProviderProp);
        }

        sslContext.init(new X509KeyManager[] { authProvider.getKeyManager() },
                        new X509TrustManager[] { authProvider.getTrustManager() },
                        null);
    }

    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(false);
    sslEngine.setNeedClientAuth(true);

    p.addLast("ssl", new SslHandler(sslEngine));
    LOG.info("SSL handler added for channel: {}", p.getChannel());
}
 
Example 10
Project: traccar-service   File: TramigoProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new TramigoFrameDecoder());
            pipeline.addLast("objectDecoder", new TramigoProtocolDecoder(TramigoProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 11
Project: traccar-service   File: BasePipelineFactory.java   Source Code and License Vote up 5 votes
private void addDynamicHandlers(ChannelPipeline pipeline) {
    if (Context.getConfig().hasKey("extra.handlers")) {
        String[] handlers = Context.getConfig().getString("extra.handlers").split(",");
        for (int i = 0; i < handlers.length; i++) {
            try {
                pipeline.addLast("extraHandler." + i, (ChannelHandler) Class.forName(handlers[i]).newInstance());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException error) {
                Log.warning(error);
            }
        }
    }
}
 
Example 12
Project: traccar-service   File: ProgressProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0));
            pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(ProgressProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 13
Project: traccar-service   File: BlackKiteProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new GalileoFrameDecoder());
            pipeline.addLast("objectDecoder", new BlackKiteProtocolDecoder(BlackKiteProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 14
Project: traccar-service   File: Pt502Protocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new Pt502FrameDecoder());
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("stringDecoder", new StringDecoder());
            pipeline.addLast("objectEncoder", new Pt502ProtocolEncoder());
            pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(Pt502Protocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 15
Project: traccar-service   File: MxtProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
                pipeline.addLast("frameDecoder", new MxtFrameDecoder());
                pipeline.addLast("objectDecoder", new MxtProtocolDecoder(MxtProtocol.this));
            }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 16
Project: traccar-service   File: TelicProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new TelicFrameDecoder());
            pipeline.addLast("stringDecoder", new StringDecoder());
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectDecoder", new TelicProtocolDecoder(TelicProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 17
Project: athena   File: BgpSessionManager.java   Source Code and License Vote up 5 votes
public void start() {
    log.debug("BGP Session Manager start.");
    isShutdown = false;

    ChannelFactory channelFactory = new NioServerSocketChannelFactory(
            newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")),
            newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d")));
    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 18
Project: traccar-service   File: ApelProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0));
            pipeline.addLast("objectDecoder", new ApelProtocolDecoder(ApelProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 19
Project: traccar-service   File: AdmProtocol.java   Source Code and License Vote up 5 votes
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 1, -3, 0));
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new AdmProtocolEncoder());
            pipeline.addLast("objectDecoder", new AdmProtocolDecoder(AdmProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
Example 20
Project: athena   File: BgpSessionManagerTest.java   Source Code and License Vote up 4 votes
/**
 * Starts up the BGP peer and connects it to the tested BgpSessionManager
 * instance.
 *
 * @param connectToSocket the socket to connect to
 */
private void connect(InetSocketAddress connectToSocket)
    throws InterruptedException {
    //
    // Setup the BGP Peer, i.e., the "remote" BGP router that will
    // initiate the BGP connection, send BGP UPDATE messages, etc.
    //
    ChannelFactory channelFactory =
        new NioClientSocketChannelFactory(
                Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool());
    ChannelPipelineFactory pipelineFactory = () -> {
        // Setup the transmitting pipeline
        ChannelPipeline pipeline = Channels.pipeline();
        pipeline.addLast("TestBgpPeerFrameDecoder",
                peerFrameDecoder);
        pipeline.addLast("TestBgpPeerChannelHandler",
                peerChannelHandler);
        return pipeline;
    };

    peerBootstrap = new ClientBootstrap(channelFactory);
    peerBootstrap.setOption("child.keepAlive", true);
    peerBootstrap.setOption("child.tcpNoDelay", true);
    peerBootstrap.setPipelineFactory(pipelineFactory);
    peerBootstrap.connect(connectToSocket);

    boolean result;
    // Wait until the OPEN message is received
    result = peerFrameDecoder.receivedOpenMessageLatch.await(
        MESSAGE_TIMEOUT_MS,
        TimeUnit.MILLISECONDS);
    assertThat(result, is(true));
    // Wait until the KEEPALIVE message is received
    result = peerFrameDecoder.receivedKeepaliveMessageLatch.await(
        MESSAGE_TIMEOUT_MS,
        TimeUnit.MILLISECONDS);
    assertThat(result, is(true));

    for (BgpSession bgpSession : bgpSessionManager.getBgpSessions()) {
        if (bgpSession.remoteInfo().bgpId().equals(BGP_PEER1_ID)) {
            bgpSession1 = bgpSession;
        }
        if (bgpSession.remoteInfo().bgpId().equals(BGP_PEER2_ID)) {
            bgpSession2 = bgpSession;
        }
        if (bgpSession.remoteInfo().bgpId().equals(BGP_PEER3_ID)) {
            bgpSession3 = bgpSession;
        }
    }
}