NETTY-423 Add ChannelPipeline.getNames()

This commit is contained in:
Trustin Lee 2011-08-02 08:43:10 +09:00
parent 5c62d54c67
commit 59a349031a
3 changed files with 37 additions and 0 deletions

View File

@ -17,6 +17,7 @@ package org.jboss.netty.channel;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -488,6 +489,11 @@ public interface ChannelPipeline {
*/ */
boolean isAttached(); boolean isAttached();
/**
* Returns the {@link List} of the handler names.
*/
List<String> getNames();
/** /**
* Converts this pipeline into an ordered {@link Map} whose keys are * Converts this pipeline into an ordered {@link Map} whose keys are
* handler names and whose values are handlers. * handler names and whose values are handlers.

View File

@ -15,8 +15,10 @@
*/ */
package org.jboss.netty.channel; package org.jboss.netty.channel;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -510,6 +512,24 @@ public class DefaultChannelPipeline implements ChannelPipeline {
return null; return null;
} }
@Override
public List<String> getNames() {
List<String> list = new ArrayList<String>();
if (name2ctx.isEmpty()) {
return list;
}
DefaultChannelHandlerContext ctx = head;
for (;;) {
list.add(ctx.getName());
ctx = ctx.next;
if (ctx == null) {
break;
}
}
return list;
}
@Override @Override
public Map<String, ChannelHandler> toMap() { public Map<String, ChannelHandler> toMap() {
Map<String, ChannelHandler> map = new LinkedHashMap<String, ChannelHandler>(); Map<String, ChannelHandler> map = new LinkedHashMap<String, ChannelHandler>();

View File

@ -15,8 +15,10 @@
*/ */
package org.jboss.netty.channel; package org.jboss.netty.channel;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLogger;
@ -340,6 +342,15 @@ public class StaticChannelPipeline implements ChannelPipeline {
return null; return null;
} }
@Override
public List<String> getNames() {
List<String> list = new ArrayList<String>();
for (StaticChannelHandlerContext ctx: contexts) {
list.add(ctx.getName());
}
return list;
}
@Override @Override
public Map<String, ChannelHandler> toMap() { public Map<String, ChannelHandler> toMap() {
Map<String, ChannelHandler> map = new LinkedHashMap<String, ChannelHandler>(); Map<String, ChannelHandler> map = new LinkedHashMap<String, ChannelHandler>();