Search in sources :

Example 1 with ServerChannelHandler

use of org.apache.camel.component.netty.handlers.ServerChannelHandler in project camel by apache.

the class DefaultServerPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline channelPipeline = 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);
        addToPipeline("ssl", channelPipeline, sslHandler);
    }
    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();
        }
        addToPipeline("encoder-" + x, channelPipeline, encoder);
    }
    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();
        }
        addToPipeline("decoder-" + x, channelPipeline, decoder);
    }
    if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
        // this must be added just before the ServerChannelHandler
        // 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());
        addToPipeline("executionHandler", channelPipeline, executionHandler);
        LOG.debug("Using OrderedMemoryAwareThreadPoolExecutor with core pool size: {}", consumer.getConfiguration().getMaximumPoolSize());
    }
    // our handler must be added last
    addToPipeline("handler", channelPipeline, new ServerChannelHandler(consumer));
    LOG.trace("Created ChannelPipeline: {}", channelPipeline);
    return channelPipeline;
}
Also used : ServerChannelHandler(org.apache.camel.component.netty.handlers.ServerChannelHandler) ExecutionHandler(org.jboss.netty.handler.execution.ExecutionHandler) ServerChannelHandler(org.apache.camel.component.netty.handlers.ServerChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler)

Aggregations

ServerChannelHandler (org.apache.camel.component.netty.handlers.ServerChannelHandler)1 ChannelHandler (org.jboss.netty.channel.ChannelHandler)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 ExecutionHandler (org.jboss.netty.handler.execution.ExecutionHandler)1 SslHandler (org.jboss.netty.handler.ssl.SslHandler)1