Package promauto.jroboplc

Source Code of promauto.jroboplc.SvcTcpServerPipelineFactoryAscii

package promauto.jroboplc;

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

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.jboss.netty.handler.codec.string.StringEncoder;


public class SvcTcpServerPipelineFactoryAscii implements
        ChannelPipelineFactory {

  private SvcTcpServer svcTcpServer;
 
 
 
  public SvcTcpServerPipelineFactoryAscii(SvcTcpServer svcTcpServer) {
    super();
    this.svcTcpServer = svcTcpServer;
  }

 
 
    public ChannelPipeline getPipeline() throws Exception {

      ChannelPipeline pipeline = pipeline();

        pipeline.addLast("framer", new DelimiterBasedFrameDecoder(
            SvcTcpServer.FRAME_LENGHT_ASCII,
            new ChannelBuffer[] {
                        ChannelBuffers.wrappedBuffer(new byte[] { '\r','\n' }),
                        ChannelBuffers.wrappedBuffer(new byte[] { '\n','\r' }),
                        ChannelBuffers.wrappedBuffer(new byte[] { '\r' })
                }));
        pipeline.addLast("decoder", new StringDecoder());
        pipeline.addLast("encoder", new StringEncoder());

        pipeline.addLast("handler", new SvcTcpServerHandlerAscii(svcTcpServer));

        return pipeline;
    }
}
TOP

Related Classes of promauto.jroboplc.SvcTcpServerPipelineFactoryAscii

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.