Anonymous class to nested class

This commit is contained in:
Trustin Lee 2009-03-12 06:24:26 +00:00
parent 3a65234df5
commit 2627751a44

View File

@ -22,8 +22,8 @@
package org.jboss.netty.channel.socket.http;
import static org.jboss.netty.channel.Channels.*;
import static org.jboss.netty.channel.socket.http.HttpTunnelingServlet.*;
import static org.jboss.netty.channel.socket.http.HttpTunnelingContextListener.*;
import static org.jboss.netty.channel.socket.http.HttpTunnelingServlet.*;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
@ -55,13 +55,7 @@ public class HttpTunnelingSessionListener implements HttpSessionListener, Channe
}
final HttpTunnelingChannelHandler handler = new HttpTunnelingChannelHandler(streaming, session, (Long) session.getServletContext().getAttribute(RECONNECT_PROP));
session.setAttribute(HANDLER_PROP, handler);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast(HttpTunnelingSessionListener.class.getName(), handler);
return pipeline;
}
});
bootstrap.setPipelineFactory(new HttpTunnelingChannelPipelineFactory(handler));
ChannelFuture future = bootstrap.connect(new LocalAddress((String) session.getServletContext().getAttribute(SERVER_CHANNEL_PROP)));
future.awaitUninterruptibly();
final Channel ch = future.getChannel();
@ -74,4 +68,24 @@ public class HttpTunnelingSessionListener implements HttpSessionListener, Channe
channel.close();
}
}
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
private static final class HttpTunnelingChannelPipelineFactory implements ChannelPipelineFactory {
private final HttpTunnelingChannelHandler handler;
HttpTunnelingChannelPipelineFactory(HttpTunnelingChannelHandler handler) {
this.handler = handler;
}
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast(HttpTunnelingSessionListener.class.getName(), handler);
return pipeline;
}
}
}