Fixed race condition in the HTTP example

This commit is contained in:
Trustin Lee 2009-03-30 18:55:32 +00:00
parent 4794030eab
commit f0b5bbacf9
4 changed files with 4 additions and 20 deletions

View File

@ -73,8 +73,7 @@ public class HttpClient {
Executors.newCachedThreadPool());
ClientBootstrap bootstrap = new ClientBootstrap(factory);
HttpClientPipelineFactory handler = new HttpClientPipelineFactory(new HttpResponseHandler());
bootstrap.setPipelineFactory(handler);
bootstrap.setPipelineFactory(new HttpClientPipelineFactory());
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

View File

@ -23,7 +23,6 @@ package org.jboss.netty.example.http;
import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.http.HttpRequestEncoder;
@ -34,12 +33,6 @@ import org.jboss.netty.handler.codec.http.HttpResponseDecoder;
* @author Andy Taylor (andy.taylor@jboss.org)
*/
public class HttpClientPipelineFactory implements ChannelPipelineFactory {
private final ChannelHandler handler;
public HttpClientPipelineFactory(HttpResponseHandler handler) {
this.handler = handler;
}
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = pipeline();
@ -47,7 +40,7 @@ public class HttpClientPipelineFactory implements ChannelPipelineFactory {
// Uncomment the following line if you don't want to handle HttpChunks.
//pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
pipeline.addLast("encoder", new HttpRequestEncoder());
pipeline.addLast("handler", handler);
pipeline.addLast("handler", new HttpResponseHandler());
return pipeline;
}
}

View File

@ -41,8 +41,7 @@ public class HttpServer {
Executors.newCachedThreadPool());
ServerBootstrap bootstrap = new ServerBootstrap(factory);
HttpServerPipelineFactory pipeline = new HttpServerPipelineFactory(new HttpRequestHandler());
bootstrap.setPipelineFactory(pipeline);
bootstrap.setPipelineFactory(new HttpServerPipelineFactory());
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);

View File

@ -23,7 +23,6 @@ package org.jboss.netty.example.http;
import static org.jboss.netty.channel.Channels.*;
import org.jboss.netty.channel.ChannelHandler;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
@ -34,12 +33,6 @@ import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
* @author Andy Taylor (andy.taylor@jboss.org)
*/
public class HttpServerPipelineFactory implements ChannelPipelineFactory {
private final ChannelHandler handler;
public HttpServerPipelineFactory(HttpRequestHandler handler) {
this.handler = handler;
}
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = pipeline();
@ -48,7 +41,7 @@ public class HttpServerPipelineFactory implements ChannelPipelineFactory {
// Uncomment the following line if you don't want to handle HttpChunks.
//pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("handler", handler);
pipeline.addLast("handler", new HttpRequestHandler());
return pipeline;
}
}