Search in sources :

Example 1 with ServerChannelHandler

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

the class DefaultServerInitializerFactory method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline channelPipeline = ch.pipeline();
    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        //TODO  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().isUsingExecutorService()) {
        // Just use EventExecutorGroup from the Netty Component
        EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService();
        addToPipeline("handler", channelPipeline, applicationExecutor, new ServerChannelHandler(consumer));
    } else {
        // still use the worker event loop group here
        addToPipeline("handler", channelPipeline, new ServerChannelHandler(consumer));
    }
    LOG.trace("Created ChannelPipeline: {}", channelPipeline);
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) ServerChannelHandler(org.apache.camel.component.netty4.handlers.ServerChannelHandler) ChannelHandler(io.netty.channel.ChannelHandler) ServerChannelHandler(org.apache.camel.component.netty4.handlers.ServerChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Aggregations

ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SslHandler (io.netty.handler.ssl.SslHandler)1 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)1 ServerChannelHandler (org.apache.camel.component.netty4.handlers.ServerChannelHandler)1