From c7821d072e37f5e2787abf205517793f7daa54d3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 9 Mar 2019 20:09:21 -0800 Subject: Refactor pipeline factory --- src/org/traccar/BasePipelineFactory.java | 51 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'src/org/traccar') 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 { 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... handlerClasses) { + for (Class handlerClass : handlerClasses) { + if (handlerClass != null) { + pipeline.addLast(Main.getInjector().getInstance(handlerClass)); } } } @@ -117,36 +118,36 @@ public abstract class BasePipelineFactory extends ChannelInitializer { 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()); -- cgit v1.2.3