Added Channels.pipeline(ChannelHandler...)

This commit is contained in:
Trustin Lee 2010-01-07 06:41:15 +00:00
parent d26dc2791f
commit bda5887238

View File

@ -18,6 +18,8 @@ package org.jboss.netty.channel;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.Map; import java.util.Map;
import org.jboss.netty.util.internal.ConversionUtil;
/** /**
* A helper class which provides various convenience methods related with * A helper class which provides various convenience methods related with
@ -62,6 +64,29 @@ public class Channels {
return new DefaultChannelPipeline(); return new DefaultChannelPipeline();
} }
/**
* Creates a new {@link ChannelPipeline} which contains the specified
* {@link ChannelHandler}s. The names of the specified handlers are
* generated automatically; the first handler's name is {@code "0"},
* the second handler's name is {@code "1"}, the third handler's name is
* {@code "2"}, and so on.
*/
public static ChannelPipeline pipeline(ChannelHandler... handlers) {
if (handlers == null) {
throw new NullPointerException("handlers");
}
ChannelPipeline newPipeline = pipeline();
for (int i = 0; i < handlers.length; i ++) {
ChannelHandler h = handlers[i];
if (h == null) {
break;
}
newPipeline.addLast(ConversionUtil.toString(i), h);
}
return newPipeline;
}
/** /**
* Creates a new {@link ChannelPipeline} which contains the same entries * Creates a new {@link ChannelPipeline} which contains the same entries
* with the specified {@code pipeline}. Please note that only the names * with the specified {@code pipeline}. Please note that only the names