diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-18 09:59:12 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-18 09:59:12 +1300 |
commit | a97966cb0335c5a8841bd0791871253a4f780d0b (patch) | |
tree | 37909ce539d2e9dc29dacbb62a555ccda00b44f6 /src/org/traccar/BasePipelineFactory.java | |
parent | dfaa98a4a02f568922684abce56317d6afda5322 (diff) | |
parent | 65361d8f0359fe2c4e02e76892a565683743b796 (diff) | |
download | trackermap-server-a97966cb0335c5a8841bd0791871253a4f780d0b.tar.gz trackermap-server-a97966cb0335c5a8841bd0791871253a4f780d0b.tar.bz2 trackermap-server-a97966cb0335c5a8841bd0791871253a4f780d0b.zip |
Merge pull request #1534 from ivanfmartinez/master
Add support for configurable handlers
Diffstat (limited to 'src/org/traccar/BasePipelineFactory.java')
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 19 |
1 files changed, 19 insertions, 0 deletions
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); + } + } + + } + } |