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;
}
}