Reverting back the previous change - some codecs might manipulate the pipeline dynamically

This commit is contained in:
Trustin Lee 2009-12-18 06:17:59 +00:00
parent 553f8cf1e9
commit 64f0a931a4

View File

@ -32,9 +32,9 @@ import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelPipelineException;
import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.DefaultChannelPipeline;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.StaticChannelPipeline;
/**
* A skeletal {@link CodecEmbedder} implementation.
@ -56,17 +56,8 @@ abstract class AbstractCodecEmbedder<E> implements CodecEmbedder<E> {
* handlers.
*/
protected AbstractCodecEmbedder(ChannelHandler... handlers) {
if (handlers == null) {
throw new NullPointerException("handlers");
}
// Initialize the pipeline.
ChannelHandler[] tmp = new ChannelHandler[handlers.length + 1];
System.arraycopy(handlers, 0, tmp, 0, handlers.length);
tmp[handlers.length] = sink;
pipeline = new EmbeddedChannelPipeline(tmp);
// Initialize the channel.
pipeline = new EmbeddedChannelPipeline();
configurePipeline(handlers);
channel = new EmbeddedChannel(pipeline, sink);
fireInitialEvents();
}
@ -90,6 +81,27 @@ abstract class AbstractCodecEmbedder<E> implements CodecEmbedder<E> {
fireChannelConnected(channel, channel.getRemoteAddress());
}
private void configurePipeline(ChannelHandler... handlers) {
if (handlers == null) {
throw new NullPointerException("handlers");
}
if (handlers.length == 0) {
throw new IllegalArgumentException(
"handlers should contain at least one " +
ChannelHandler.class.getSimpleName() + '.');
}
for (int i = 0; i < handlers.length; i ++) {
ChannelHandler h = handlers[i];
if (h == null) {
throw new NullPointerException("handlers[" + i + "]");
}
pipeline.addLast(String.valueOf(i), handlers[i]);
}
pipeline.addLast("SINK", sink);
}
public boolean finish() {
fireChannelDisconnected(channel);
fireChannelUnbound(channel);
@ -206,10 +218,10 @@ abstract class AbstractCodecEmbedder<E> implements CodecEmbedder<E> {
}
}
private static final class EmbeddedChannelPipeline extends StaticChannelPipeline {
private static final class EmbeddedChannelPipeline extends DefaultChannelPipeline {
EmbeddedChannelPipeline(ChannelHandler... handlers) {
super(handlers);
EmbeddedChannelPipeline() {
super();
}
@Override