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

The following examples show how to use org.jboss.netty.channel.ChannelPipeline#addBefore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CrateNettyHttpServerTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = super.getPipeline();

    HttpBlobHandler blobHandler = new HttpBlobHandler(transport.blobService, transport.blobIndices, sslEnabled);
    pipeline.addBefore("aggregator", "blob_handler", blobHandler);

    if (sslEnabled) {
        // required for blob support with ssl enabled (zero copy doesn't work with https)
        pipeline.addBefore("blob_handler", "chunkedWriter", new ChunkedWriteHandler());
    }
    return pipeline;
}
 
Example 2
Source File: AbstractExecutorAwareChannelPipelineFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeLine = super.getPipeline();
    pipeLine.addBefore(HandlerConstants.CORE_HANDLER, "countHandler", getConnectionCountHandler());
    
    return pipeLine;
}
 
Example 3
Source File: ImapChannelUpstreamHandler.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    try (Closeable closeable = IMAPMDCContext.from(ctx, attributes)) {
        imapCommandsMetric.increment();
        ImapSession session = (ImapSession) attributes.get(ctx.getChannel());
        ImapResponseComposer response = (ImapResponseComposer) ctx.getAttachment();
        ImapMessage message = (ImapMessage) e.getMessage();
        ChannelPipeline cp = ctx.getPipeline();

        try {
            if (cp.get(NettyConstants.EXECUTION_HANDLER) != null) {
                cp.addBefore(NettyConstants.EXECUTION_HANDLER, NettyConstants.HEARTBEAT_HANDLER, heartbeatHandler);
            } else {
                cp.addBefore(NettyConstants.CORE_HANDLER, NettyConstants.HEARTBEAT_HANDLER, heartbeatHandler);

            }
            final ResponseEncoder responseEncoder = new ResponseEncoder(encoder, response);
            processor.process(message, responseEncoder, session);

            if (session.getState() == ImapSessionState.LOGOUT) {
                // Make sure we close the channel after all the buffers were flushed out
                Channel channel = ctx.getChannel();
                if (channel.isConnected()) {
                    channel.write(ChannelBuffers.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
                }
            }
            final IOException failure = responseEncoder.getFailure();

            if (failure != null) {
                LOGGER.info(failure.getMessage());
                LOGGER.debug("Failed to write {}", message, failure);
                throw failure;
            }
        } finally {
            ctx.getPipeline().remove(NettyConstants.HEARTBEAT_HANDLER);
        }

        super.messageReceived(ctx, e);
    }
}