Package se.cgbystrom.netty.thrift.http

Source Code of se.cgbystrom.netty.thrift.http.ThriftHttpClientPipelineFactory

package se.cgbystrom.netty.thrift.http;

import static org.jboss.netty.channel.Channels.pipeline;

import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
import org.jboss.netty.handler.codec.http.HttpRequestEncoder;
import org.jboss.netty.handler.codec.http.HttpResponseDecoder;

import se.cgbystrom.netty.thrift.ThriftHandler;

/**
* Pipeline factory for Thrift Http client
*
* @author Davide Inglima <limacat@gmail.com>
*/
public class ThriftHttpClientPipelineFactory implements ChannelPipelineFactory {

    private final ThriftHandler handler;
   
    private final String host;
   
    private final String uri;

    public ThriftHttpClientPipelineFactory(ThriftHandler handler, String host, String uri) {
        this.handler = handler;
        this.host = host;
        this.uri = uri;
    }

  @Override
  public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = pipeline();
        pipeline.addLast("requestEncoder", new HttpRequestEncoder());
        pipeline.addLast("channelEncoder", new HttpEncoder(host, uri));
        pipeline.addLast("responseDecoder", new HttpResponseDecoder());
    pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
    pipeline.addLast("thriftHandler", (ChannelHandler)handler);
    return pipeline;
  }
}
TOP

Related Classes of se.cgbystrom.netty.thrift.http.ThriftHttpClientPipelineFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.