diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 20:00:11 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 20:00:11 -0800 |
commit | c7e9f996ed7d183442a7dd2fbbc5c9329981f261 (patch) | |
tree | 7b4ffe903970396e04a2bcdbe0acd66cba156395 /src/org/traccar | |
parent | 312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd (diff) | |
download | trackermap-server-c7e9f996ed7d183442a7dd2fbbc5c9329981f261.tar.gz trackermap-server-c7e9f996ed7d183442a7dd2fbbc5c9329981f261.tar.bz2 trackermap-server-c7e9f996ed7d183442a7dd2fbbc5c9329981f261.zip |
Refactor maintenance handler
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 4 | ||||
-rw-r--r-- | src/org/traccar/MainModule.java | 14 | ||||
-rw-r--r-- | src/org/traccar/handler/events/MaintenanceEventHandler.java | 21 |
3 files changed, 30 insertions, 9 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index e3328a524..57e7322aa 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -59,7 +59,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { private boolean eventsEnabled; private int timeout; - private MaintenanceEventHandler maintenanceEventHandler; private DriverEventHandler driverEventHandler; public BasePipelineFactory(TrackerServer server, String protocol) { @@ -71,7 +70,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { } if (eventsEnabled) { - maintenanceEventHandler = new MaintenanceEventHandler(); driverEventHandler = new DriverEventHandler(); } } @@ -153,7 +151,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { Main.getInjector().getInstance(GeofenceEventHandler.class), Main.getInjector().getInstance(AlertEventHandler.class), Main.getInjector().getInstance(IgnitionEventHandler.class), - maintenanceEventHandler, + Main.getInjector().getInstance(MaintenanceEventHandler.class), driverEventHandler); } diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java index 16a78b109..b459d824d 100644 --- a/src/org/traccar/MainModule.java +++ b/src/org/traccar/MainModule.java @@ -27,6 +27,7 @@ import org.traccar.database.DataManager; import org.traccar.database.DeviceManager; import org.traccar.database.GeofenceManager; import org.traccar.database.IdentityManager; +import org.traccar.database.MaintenancesManager; import org.traccar.database.StatisticsManager; import org.traccar.geocoder.AddressFormat; import org.traccar.geocoder.BanGeocoder; @@ -63,6 +64,7 @@ import org.traccar.handler.events.CommandResultEventHandler; import org.traccar.handler.events.FuelDropEventHandler; import org.traccar.handler.events.GeofenceEventHandler; import org.traccar.handler.events.IgnitionEventHandler; +import org.traccar.handler.events.MaintenanceEventHandler; import org.traccar.handler.events.MotionEventHandler; import org.traccar.handler.events.OverspeedEventHandler; import org.traccar.reports.model.TripsConfig; @@ -122,6 +124,11 @@ public class MainModule extends AbstractModule { return Context.getAttributesManager(); } + @Provides + public static MaintenancesManager provideMaintenancesManager() { + return Context.getMaintenancesManager(); + } + @Singleton @Provides public static StatisticsManager provideStatisticsManager(Config config, DataManager dataManager, Client client) { @@ -344,6 +351,13 @@ public class MainModule extends AbstractModule { return new IgnitionEventHandler(identityManager); } + @Singleton + @Provides + public static MaintenanceEventHandler provideMaintenanceEventHandler( + IdentityManager identityManager, MaintenancesManager maintenancesManager) { + return new MaintenanceEventHandler(identityManager, maintenancesManager); + } + @Override protected void configure() { binder().requireExplicitBindings(); diff --git a/src/org/traccar/handler/events/MaintenanceEventHandler.java b/src/org/traccar/handler/events/MaintenanceEventHandler.java index 80d9c0d91..93ae74142 100644 --- a/src/org/traccar/handler/events/MaintenanceEventHandler.java +++ b/src/org/traccar/handler/events/MaintenanceEventHandler.java @@ -20,7 +20,8 @@ import java.util.HashMap; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.Context; +import org.traccar.database.IdentityManager; +import org.traccar.database.MaintenancesManager; import org.traccar.model.Event; import org.traccar.model.Maintenance; import org.traccar.model.Position; @@ -28,21 +29,29 @@ import org.traccar.model.Position; @ChannelHandler.Sharable public class MaintenanceEventHandler extends BaseEventHandler { + private final IdentityManager identityManager; + private final MaintenancesManager maintenancesManager; + + public MaintenanceEventHandler(IdentityManager identityManager, MaintenancesManager maintenancesManager) { + this.identityManager = identityManager; + this.maintenancesManager = maintenancesManager; + } + @Override protected Map<Event, Position> analyzePosition(Position position) { - if (Context.getIdentityManager().getById(position.getDeviceId()) == null - || !Context.getIdentityManager().isLatestPosition(position)) { + if (identityManager.getById(position.getDeviceId()) == null + || !identityManager.isLatestPosition(position)) { return null; } - Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + Position lastPosition = identityManager.getLastPosition(position.getDeviceId()); if (lastPosition == null) { return null; } Map<Event, Position> events = new HashMap<>(); - for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) { - Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); + for (long maintenanceId : maintenancesManager.getAllDeviceItems(position.getDeviceId())) { + Maintenance maintenance = maintenancesManager.getById(maintenanceId); if (maintenance.getPeriod() != 0) { double oldValue = lastPosition.getDouble(maintenance.getType()); double newValue = position.getDouble(maintenance.getType()); |