Search in sources :

Example 26 with ChannelHandler

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

the class HttpClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    SslHandler sslHandler = configureClientSSLOnDemand();
    if (sslHandler != null) {
        // must close on SSL exception
        sslHandler.setCloseOnSSLException(true);
        LOG.debug("Client SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }
    pipeline.addLast("http", new HttpClientCodec());
    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();
        }
        pipeline.addLast("decoder-" + x, 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();
        }
        pipeline.addLast("encoder-" + x, encoder);
    }
    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);
        pipeline.addLast("timeout", timeout);
    }
    // handler to route Camel messages
    pipeline.addLast("handler", new HttpClientChannelHandler(producer));
    return pipeline;
}
Also used : HttpClientChannelHandler(org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler) ChannelHandlerFactory(org.apache.camel.component.netty.ChannelHandlerFactory) ReadTimeoutHandler(org.jboss.netty.handler.timeout.ReadTimeoutHandler) HttpClientChannelHandler(org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 27 with ChannelHandler

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

the class HttpServerPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();
    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        // must close on SSL exception
        sslHandler.setCloseOnSSLException(true);
        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));
    List<ChannelHandler> decoders = consumer.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();
        }
        pipeline.addLast("decoder-" + x, decoder);
    }
    pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    List<ChannelHandler> encoders = consumer.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();
        }
        pipeline.addLast("encoder-" + x, encoder);
    }
    if (supportCompressed()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
        // this must be added just before the HttpServerMultiplexChannelHandler
        // use ordered thread pool, to ensure we process the events in order, and can send back
        // replies in the expected order. eg this is required by TCP.
        // and use a Camel thread factory so we have consistent thread namings
        ExecutionHandler executionHandler = new ExecutionHandler(consumer.getEndpoint().getComponent().getExecutorService());
        pipeline.addLast("executionHandler", executionHandler);
        LOG.debug("Using OrderedMemoryAwareThreadPoolExecutor with core pool size: {}", consumer.getConfiguration().getMaximumPoolSize());
    }
    int port = consumer.getConfiguration().getPort();
    ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port).getChannelHandler();
    pipeline.addLast("handler", handler);
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) ChannelHandlerFactory(org.apache.camel.component.netty.ChannelHandlerFactory) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) ExecutionHandler(org.jboss.netty.handler.execution.ExecutionHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Example 28 with ChannelHandler

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

the class NettyHttpConfiguration method copy.

@Override
public NettyHttpConfiguration copy() {
    try {
        // clone as NettyHttpConfiguration
        NettyHttpConfiguration answer = (NettyHttpConfiguration) clone();
        // make sure the lists is copied in its own instance
        List<ChannelHandler> encodersCopy = new ArrayList<ChannelHandler>(getEncoders());
        answer.setEncoders(encodersCopy);
        List<ChannelHandler> decodersCopy = new ArrayList<ChannelHandler>(getDecoders());
        answer.setDecoders(decodersCopy);
        return answer;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeCamelException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ChannelHandler(org.jboss.netty.channel.ChannelHandler)

Example 29 with ChannelHandler

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

the class NettyHttpGetWithInvalidMessageTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    // setup the String encoder and decoder 
    StringDecoder stringDecoder = new StringDecoder();
    registry.bind("string-decoder", stringDecoder);
    StringEncoder stringEncoder = new StringEncoder();
    registry.bind("string-encoder", stringEncoder);
    List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
    decoders.add(stringDecoder);
    List<ChannelHandler> encoders = new ArrayList<ChannelHandler>();
    encoders.add(stringEncoder);
    registry.bind("encoders", encoders);
    registry.bind("decoders", decoders);
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) ArrayList(java.util.ArrayList) StringDecoder(org.jboss.netty.handler.codec.string.StringDecoder) ChannelHandler(org.jboss.netty.channel.ChannelHandler)

Example 30 with ChannelHandler

use of org.jboss.netty.channel.ChannelHandler in project pinpoint by naver.

the class Connection method connect.

void connect(SocketAddressProvider remoteAddressProvider, boolean reconnect, PipelineFactory pipelineFactory) {
    Objects.requireNonNull(remoteAddressProvider, "remoteAddress");
    final ChannelPipeline pipeline = pipelineFactory.newPipeline();
    Timer channelTimer = createTimer("Pinpoint-PinpointClientHandler-Timer");
    final ChannelHandler writeTimeout = new WriteTimeoutHandler(channelTimer, 3000, TimeUnit.MILLISECONDS);
    pipeline.addLast("writeTimeout", writeTimeout);
    this.pinpointClientHandler = this.clientHandlerFactory.newClientHandler(connectionFactory, remoteAddressProvider, channelTimer, reconnect);
    if (pinpointClientHandler instanceof SimpleChannelHandler) {
        pipeline.addLast("socketHandler", (SimpleChannelHandler) this.pinpointClientHandler);
    } else {
        throw new IllegalArgumentException("invalid pinpointClientHandler");
    }
    final SocketAddress remoteAddress = remoteAddressProvider.resolve();
    this.connectFuture = connect0(remoteAddress, pipeline);
}
Also used : Timer(org.jboss.netty.util.Timer) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) WriteTimeoutHandler(org.jboss.netty.handler.timeout.WriteTimeoutHandler) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) SocketAddress(java.net.SocketAddress) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ChannelHandler (org.jboss.netty.channel.ChannelHandler)30 Callable (java.util.concurrent.Callable)12 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)9 ArrayList (java.util.ArrayList)5 MessageInput (org.graylog2.plugin.inputs.MessageInput)5 SimpleChannelHandler (org.jboss.netty.channel.SimpleChannelHandler)5 SslHandler (org.jboss.netty.handler.ssl.SslHandler)5 ReadTimeoutHandler (org.jboss.netty.handler.timeout.ReadTimeoutHandler)5 File (java.io.File)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketAddress (java.net.SocketAddress)4 Configuration (org.graylog2.plugin.configuration.Configuration)4 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4 Channel (org.jboss.netty.channel.Channel)4 Test (org.junit.Test)4 NettyHttpDatabusRelayConnection (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection)3 NettyHttpDatabusRelayConnectionInspector (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnectionInspector)3 Checkpoint (com.linkedin.databus.core.Checkpoint)3 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)3 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)3