Skip to content

Instantly share code, notes, and snippets.

@yongboy
Created March 20, 2012 03:47
Show Gist options
  • Save yongboy/2130999 to your computer and use it in GitHub Desktop.
Save yongboy/2130999 to your computer and use it in GitHub Desktop.
QueueDaemon.java
/**
* 简单队列启动入口
*
* @author yongboy
* @time 2012-3-19
* @version 1.0
*/
public class QueueDaemon {
private int port;
private QueueService queueService;
public QueueDaemon(int port, QueueService queueService) {
this.port = port;
this.queueService = queueService;
}
public void start() {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("handler",
new HttpRequestHandler(queueService));
return pipeline;
}
});
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.reuseAddress", true);
bootstrap.setOption("child.connectTimeoutMillis", 100);
bootstrap.bind(new InetSocketAddress(port));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment