From 2776f3e5a7d837feff46c003ec32c162ac71b970 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 10:08:48 +1300 Subject: Clean up adding dynamic handlers --- src/org/traccar/BasePipelineFactory.java | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/org') 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); + } } } - } - + } -- cgit v1.2.3