private SerializerDeserializer serDeser;
@Inject
public TestListener(Assignment assignment, @Named("s4.comm.timeout") int timeout, SerializerDeserializer serDeser) {
// wait for an assignment
ClusterNode node = assignment.assignClusterNode();
this.serDeser = serDeser;
ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() {
ChannelPipeline p = Channels.pipeline();
p.addLast("1", new LengthFieldBasedFrameDecoder(999999, 0, 4, 0, 4));
p.addLast("2", new MyChannelHandler());
return p;
}
});
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.reuseAddress", true);
bootstrap.setOption("child.connectTimeoutMillis", timeout);
bootstrap.setOption("readWriteFair", true);
Channel c = bootstrap.bind(new InetSocketAddress(node.getPort()));
channels.add(c);
zkClient = new ZkClient("localhost:2181");
}