From bda588723862416e1f8e45563e9c25e5ba3d5292 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 7 Jan 2010 06:41:15 +0000 Subject: [PATCH] Added Channels.pipeline(ChannelHandler...) --- .../org/jboss/netty/channel/Channels.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/org/jboss/netty/channel/Channels.java b/src/main/java/org/jboss/netty/channel/Channels.java index 125716700e..6fb30c7b99 100644 --- a/src/main/java/org/jboss/netty/channel/Channels.java +++ b/src/main/java/org/jboss/netty/channel/Channels.java @@ -18,6 +18,8 @@ package org.jboss.netty.channel; import java.net.SocketAddress; import java.util.Map; +import org.jboss.netty.util.internal.ConversionUtil; + /** * A helper class which provides various convenience methods related with @@ -62,6 +64,29 @@ public class Channels { 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 * with the specified {@code pipeline}. Please note that only the names