diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-10-24 14:10:00 +0400 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-10-24 14:10:00 +0400 |
commit | d7f4e49f89a878008101b58eaa207f89068cabba (patch) | |
tree | 507c15da107559dea485f8b040ca1ccfce8cab57 /src/org/traccar/BasePipelineFactory.java | |
parent | 3a008c877056234e525587dbb339e5c950748b9a (diff) | |
download | trackermap-server-d7f4e49f89a878008101b58eaa207f89068cabba.tar.gz trackermap-server-d7f4e49f89a878008101b58eaa207f89068cabba.tar.bz2 trackermap-server-d7f4e49f89a878008101b58eaa207f89068cabba.zip |
Search unwrapped handlers by class
Diffstat (limited to 'src/org/traccar/BasePipelineFactory.java')
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index d511af214..401c42d8b 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -44,6 +44,7 @@ import org.traccar.processing.ComputedAttributesHandler; import org.traccar.processing.CopyAttributesHandler; import java.net.InetSocketAddress; +import java.util.Map; public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { @@ -241,6 +242,21 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { } } + public static <T extends ChannelHandler> T getHandler(ChannelPipeline pipeline, Class<T> clazz) { + for (Map.Entry<String, ChannelHandler> handlerEntry : pipeline) { + ChannelHandler handler = handlerEntry.getValue(); + if (handler instanceof WrapperInboundHandler) { + handler = ((WrapperInboundHandler) handler).getWrappedHandler(); + } else if (handler instanceof WrapperOutboundHandler) { + handler = ((WrapperOutboundHandler) handler).getWrappedHandler(); + } + if (clazz.isAssignableFrom(handler.getClass())) { + return (T) handler; + } + } + return null; + } + @Override protected void initChannel(Channel channel) throws Exception { final ChannelPipeline pipeline = channel.pipeline(); |