aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/BasePipelineFactory.java4
-rw-r--r--src/org/traccar/MainModule.java14
-rw-r--r--src/org/traccar/handler/events/MaintenanceEventHandler.java21
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());