Search in sources :

Example 21 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.

the class DefaultClientPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // create a new pipeline
    ChannelPipeline channelPipeline = Channels.pipeline();
    SslHandler sslHandler = configureClientSSLOnDemand();
    if (sslHandler != null) {
        // must close on SSL exception
        sslHandler.setCloseOnSSLException(true);
        LOG.debug("Client SSL handler configured and added to the ChannelPipeline: {}", sslHandler);
        addToPipeline("ssl", channelPipeline, sslHandler);
    }
    List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
    for (int x = 0; x < decoders.size(); x++) {
        ChannelHandler decoder = decoders.get(x);
        if (decoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
        }
        addToPipeline("decoder-" + x, channelPipeline, decoder);
    }
    List<ChannelHandler> encoders = producer.getConfiguration().getEncoders();
    for (int x = 0; x < encoders.size(); x++) {
        ChannelHandler encoder = encoders.get(x);
        if (encoder instanceof ChannelHandlerFactory) {
            // use the factory to create a new instance of the channel as it may not be shareable
            encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
        }
        addToPipeline("encoder-" + x, channelPipeline, encoder);
    }
    // do we use request timeout?
    if (producer.getConfiguration().getRequestTimeout() > 0) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
        }
        ChannelHandler timeout = new ReadTimeoutHandler(producer.getEndpoint().getTimer(), producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
        addToPipeline("timeout", channelPipeline, timeout);
    }
    // our handler must be added last
    addToPipeline("handler", channelPipeline, new ClientChannelHandler(producer));
    LOG.trace("Created ChannelPipeline: {}", channelPipeline);
    return channelPipeline;
}
Also used : ReadTimeoutHandler(org.jboss.netty.handler.timeout.ReadTimeoutHandler) ClientChannelHandler(org.apache.camel.component.netty.handlers.ClientChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler) ClientChannelHandler(org.apache.camel.component.netty.handlers.ClientChannelHandler)

Example 22 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.

the class HttpServerSharedPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();
    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
    }
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    pipeline.addLast("handler", channelFactory.getChannelHandler());
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 23 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.

the class NettyUdpConnectedSendTest method createNettyUdpReceiver.

public void createNettyUdpReceiver() {
    bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory());
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline channelPipeline = Channels.pipeline();
            channelPipeline.addLast("StringDecoder", new StringDecoder(CharsetUtil.UTF_8));
            channelPipeline.addLast("ContentHandler", new ContentHandler());
            return channelPipeline;
        }
    });
}
Also used : NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) StringDecoder(org.jboss.netty.handler.codec.string.StringDecoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 24 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project databus by linkedin.

the class GenericHttpClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    if (_channelGroup != null)
        pipeline.addLast("auto group register ", new ConnectionChannelRegistrationHandler(_channelGroup));
    if (Logger.getRootLogger().isTraceEnabled()) {
        LOG.debug("Adding Netty tracing");
        pipeline.addLast("netty client traffic", new LoggingHandler("netty client traffic", InternalLogLevel.DEBUG, true));
    }
    if (null != _containerStatsCollector) {
        pipeline.addLast("inbound statistics collector", new InboundContainerStatisticsCollectingHandler(_containerStatsCollector));
    }
    ExtendedReadTimeoutHandler readTimeoutHandler = new ExtendedReadTimeoutHandler("client call ", _timeoutTimer, _readTimeoutMs, true);
    pipeline.addLast(READ_TIMEOUT_HANDLER_NAME, readTimeoutHandler);
    pipeline.addLast("codec", new HttpClientCodec());
    pipeline.addLast("http logger", new HttpRequestLoggingHandler());
    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());
    //pipeline.addLast("handler", new GenericHttpResponseHandler(_responseProcessor, _keepAlive));
    pipeline.addLast("handler", _handler);
    //add a handler to deal with write timeouts
    pipeline.addLast("client request write timeout handler", new ExtendedWriteTimeoutHandler("netty client traffic", _timeoutTimer, _writeTimeoutMs, true));
    return pipeline;
}
Also used : ConnectionChannelRegistrationHandler(com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ExtendedReadTimeoutHandler(com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler) ExtendedWriteTimeoutHandler(com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) InboundContainerStatisticsCollectingHandler(com.linkedin.databus2.core.container.netty.InboundContainerStatisticsCollectingHandler) HttpContentDecompressor(org.jboss.netty.handler.codec.http.HttpContentDecompressor)

Example 25 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project databus by linkedin.

the class BootstrapStartScnHttpResponseProcessor method onTargetScnConnectSuccess.

void onTargetScnConnectSuccess() {
    _curState = State.TARGET_SCN_REQUEST_WRITE;
    ChannelPipeline channelPipeline = _channel.getPipeline();
    _readTimeOutHandler = (ExtendedReadTimeoutHandler) channelPipeline.get(GenericHttpClientPipelineFactory.READ_TIMEOUT_HANDLER_NAME);
    _readTimeOutHandler.start(channelPipeline.getContext(_readTimeOutHandler));
    BootstrapTargetScnHttpResponseProcessor targetResponseProcessor = new BootstrapTargetScnHttpResponseProcessor(this, _callback, _callbackStateReuse, _checkpoint, _remoteExceptionHandler, _readTimeOutHandler);
    final String url = createTargetScnRequestUrl();
    LOG.info("Sending " + url);
    // Prepare the HTTP request.
    HttpRequest request = createEmptyRequest(url);
    sendRequest(request, new TargetScnRequestResultListener(), targetResponseProcessor);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)105 InetSocketAddress (java.net.InetSocketAddress)32 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)29 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)24 Channel (org.jboss.netty.channel.Channel)23 SocketAddress (java.net.SocketAddress)20 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)17 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)16 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)15 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)15 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)15 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)13 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)13 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)13 Checkpoint (com.linkedin.databus.core.Checkpoint)12 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)12 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)11 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)11 Test (org.testng.annotations.Test)11 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)10