Package org.sdnplatform.sync.internal.config.bootstrap

Source Code of org.sdnplatform.sync.internal.config.bootstrap.BootstrapPipelineFactory

package org.sdnplatform.sync.internal.config.bootstrap;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.util.ExternalResourceReleasable;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;
import org.sdnplatform.sync.internal.rpc.ThriftFrameDecoder;
import org.sdnplatform.sync.internal.rpc.ThriftFrameEncoder;

public class BootstrapPipelineFactory
    implements ChannelPipelineFactory, ExternalResourceReleasable {
    private Bootstrap bootstrap;
    private static final int maxFrameSize = 1024 * 1024 * 10;
    protected Timer timer;
   
    public BootstrapPipelineFactory(Bootstrap bootstrap) {
        super();
        this.bootstrap = bootstrap;
        this.timer = new HashedWheelTimer();
    }

    @Override
    public ChannelPipeline getPipeline() throws Exception {
        BootstrapChannelHandler handler =
                new BootstrapChannelHandler(bootstrap);
        ChannelPipeline pipeline = Channels.pipeline();

        pipeline.addLast("frameDecoder",
                         new ThriftFrameDecoder(maxFrameSize));
        pipeline.addLast("frameEncoder",
                         new ThriftFrameEncoder());
        pipeline.addLast("timeout",
                         new BootstrapTimeoutHandler(timer, 10));

        pipeline.addLast("handler", handler);

        return pipeline;
    }

    @Override
    public void releaseExternalResources() {
        timer.stop();
    }   
}
TOP

Related Classes of org.sdnplatform.sync.internal.config.bootstrap.BootstrapPipelineFactory

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.