Created
March 20, 2012 03:47
-
-
Save yongboy/2130999 to your computer and use it in GitHub Desktop.
QueueDaemon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 简单队列启动入口 | |
* | |
* @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