diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 20:09:21 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 20:09:21 -0800 |
commit | c7821d072e37f5e2787abf205517793f7daa54d3 (patch) | |
tree | a6df8fdf8de98c71c5d593fcbfaf08808ac4d017 | |
parent | 69ebfe201e6399340545e167110e87fdd4e16a6b (diff) | |
download | trackermap-server-c7821d072e37f5e2787abf205517793f7daa54d3.tar.gz trackermap-server-c7821d072e37f5e2787abf205517793f7daa54d3.tar.bz2 trackermap-server-c7821d072e37f5e2787abf205517793f7daa54d3.zip |
Refactor pipeline factory
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index f8800ada2..b3d37f689 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -70,10 +70,11 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { protected abstract void addProtocolHandlers(PipelineBuilder pipeline); - private void addHandlers(ChannelPipeline pipeline, ChannelHandler... handlers) { - for (ChannelHandler handler : handlers) { - if (handler != null) { - pipeline.addLast(handler); + @SafeVarargs + private final void addHandlers(ChannelPipeline pipeline, Class<? extends ChannelHandler>... handlerClasses) { + for (Class<? extends ChannelHandler> handlerClass : handlerClasses) { + if (handlerClass != null) { + pipeline.addLast(Main.getInjector().getInstance(handlerClass)); } } } @@ -117,36 +118,36 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { addHandlers( pipeline, - Main.getInjector().getInstance(GeolocationHandler.class), - Main.getInjector().getInstance(HemisphereHandler.class), - Main.getInjector().getInstance(DistanceHandler.class), - Main.getInjector().getInstance(RemoteAddressHandler.class)); + GeolocationHandler.class, + HemisphereHandler.class, + DistanceHandler.class, + RemoteAddressHandler.class); addDynamicHandlers(pipeline); addHandlers( pipeline, - Main.getInjector().getInstance(FilterHandler.class), - Main.getInjector().getInstance(GeocoderHandler.class), - Main.getInjector().getInstance(MotionHandler.class), - Main.getInjector().getInstance(EngineHoursHandler.class), - Main.getInjector().getInstance(CopyAttributesHandler.class), - Main.getInjector().getInstance(ComputedAttributesHandler.class), - Main.getInjector().getInstance(WebDataHandler.class), - Main.getInjector().getInstance(DefaultDataHandler.class)); + FilterHandler.class, + GeocoderHandler.class, + MotionHandler.class, + EngineHoursHandler.class, + CopyAttributesHandler.class, + ComputedAttributesHandler.class, + WebDataHandler.class, + DefaultDataHandler.class); if (eventsEnabled) { addHandlers( pipeline, - Main.getInjector().getInstance(CommandResultEventHandler.class), - Main.getInjector().getInstance(OverspeedEventHandler.class), - Main.getInjector().getInstance(FuelDropEventHandler.class), - Main.getInjector().getInstance(MotionEventHandler.class), - Main.getInjector().getInstance(GeofenceEventHandler.class), - Main.getInjector().getInstance(AlertEventHandler.class), - Main.getInjector().getInstance(IgnitionEventHandler.class), - Main.getInjector().getInstance(MaintenanceEventHandler.class), - Main.getInjector().getInstance(DriverEventHandler.class)); + CommandResultEventHandler.class, + OverspeedEventHandler.class, + FuelDropEventHandler.class, + MotionEventHandler.class, + GeofenceEventHandler.class, + AlertEventHandler.class, + IgnitionEventHandler.class, + MaintenanceEventHandler.class, + DriverEventHandler.class); } pipeline.addLast(new MainEventHandler()); |