From 65361d8f0359fe2c4e02e76892a565683743b796 Mon Sep 17 00:00:00 2001 From: Ivan Martinez Date: Mon, 16 Nov 2015 23:50:14 -0200 Subject: add support for configurable handlers --- src/org/traccar/BasePipelineFactory.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index c0952db86..7273d51cf 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -19,6 +19,7 @@ import java.net.InetSocketAddress; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.ChannelEvent; +import org.jboss.netty.channel.ChannelHandler; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; @@ -130,6 +131,9 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { pipeline.addLast("geocoder", reverseGeocoderHandler); } pipeline.addLast("remoteAddress", new RemoteAddressHandler()); + + addDynamicHandlers(pipeline, "extraHandler", "extra.handlers"); + if (Context.getDataManager() != null) { pipeline.addLast("dataHandler", new DefaultDataHandler()); } @@ -140,4 +144,19 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { return pipeline; } + private void addDynamicHandlers(ChannelPipeline pipeline, String id, String key) { + final String[] extraHandlers = Context.getConfig().getString(key,"").split(","); + int i = 0; + for (String extraHandler : extraHandlers) { + try { + Class c = Class.forName(extraHandler); + i++; + pipeline.addLast(id + "."+i, (ChannelHandler)c.newInstance()); + } catch (Throwable e) { + Log.error("Error loading handler : " + extraHandler + " " + e); + } + } + + } + } -- cgit v1.2.3