diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-18 10:08:48 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-18 10:08:48 +1300 |
commit | 2776f3e5a7d837feff46c003ec32c162ac71b970 (patch) | |
tree | 103db4f291cd49fe1865128c92799dd1697e94c5 | |
parent | a97966cb0335c5a8841bd0791871253a4f780d0b (diff) | |
download | trackermap-server-2776f3e5a7d837feff46c003ec32c162ac71b970.tar.gz trackermap-server-2776f3e5a7d837feff46c003ec32c162ac71b970.tar.bz2 trackermap-server-2776f3e5a7d837feff46c003ec32c162ac71b970.zip |
Clean up adding dynamic handlers
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 7273d51cf..6b877883d 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -120,7 +120,9 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { if (Context.isLoggerEnabled()) { pipeline.addLast("logger", new StandardLoggingHandler()); } + addSpecificHandlers(pipeline); + if (filterHandler != null) { pipeline.addLast("filter", filterHandler); } @@ -132,7 +134,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { } pipeline.addLast("remoteAddress", new RemoteAddressHandler()); - addDynamicHandlers(pipeline, "extraHandler", "extra.handlers"); + addDynamicHandlers(pipeline); if (Context.getDataManager() != null) { pipeline.addLast("dataHandler", new DefaultDataHandler()); @@ -144,19 +146,17 @@ 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); + private void addDynamicHandlers(ChannelPipeline pipeline) { + if (Context.getConfig().hasKey("extra.handlers")) { + String[] handlers = Context.getConfig().getString("extra.handlers").split(","); + for (int i = 0; i < handlers.length; i++) { + try { + pipeline.addLast("extraHandler." + i, (ChannelHandler) Class.forName(handlers[i]).newInstance()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException error) { + Log.warning(error); + } } } - } - + } |