aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 17:04:08 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 17:04:08 -0800
commit5c084a0b2961dbfc3cd85a386fefe0b0da6c0c44 (patch)
tree637b9f89086bad578bbad04fd52e80bf379b8beb /src/org/traccar
parent2a584c67a1663897d98e7c64fe161c88b30ef314 (diff)
downloadtraccar-server-5c084a0b2961dbfc3cd85a386fefe0b0da6c0c44.tar.gz
traccar-server-5c084a0b2961dbfc3cd85a386fefe0b0da6c0c44.tar.bz2
traccar-server-5c084a0b2961dbfc3cd85a386fefe0b0da6c0c44.zip
Refactor ignition event handler
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BasePipelineFactory.java4
-rw-r--r--src/org/traccar/MainModule.java7
-rw-r--r--src/org/traccar/handler/events/IgnitionEventHandler.java16
3 files changed, 19 insertions, 8 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 5e194c856..550145860 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -58,7 +58,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private boolean eventsEnabled;
private int timeout;
- private IgnitionEventHandler ignitionEventHandler;
private MaintenanceEventHandler maintenanceEventHandler;
private DriverEventHandler driverEventHandler;
@@ -71,7 +70,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
}
if (eventsEnabled) {
- ignitionEventHandler = new IgnitionEventHandler();
maintenanceEventHandler = new MaintenanceEventHandler();
driverEventHandler = new DriverEventHandler();
}
@@ -156,7 +154,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
Main.getInjector().getInstance(MotionEventHandler.class),
Main.getInjector().getInstance(GeofenceEventHandler.class),
Main.getInjector().getInstance(AlertEventHandler.class),
- ignitionEventHandler,
+ Main.getInjector().getInstance(IgnitionEventHandler.class),
maintenanceEventHandler,
driverEventHandler);
}
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index 3f196972f..8ad89529f 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -61,6 +61,7 @@ import org.traccar.handler.events.AlertEventHandler;
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.MotionEventHandler;
import org.traccar.handler.events.OverspeedEventHandler;
import org.traccar.reports.model.TripsConfig;
@@ -327,6 +328,12 @@ public class MainModule extends AbstractModule {
return new AlertEventHandler(config, identityManager);
}
+ @Singleton
+ @Provides
+ public static IgnitionEventHandler provideIgnitionEventHandler(IdentityManager identityManager) {
+ return new IgnitionEventHandler(identityManager);
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/handler/events/IgnitionEventHandler.java b/src/org/traccar/handler/events/IgnitionEventHandler.java
index 7a83f45b7..ec133bafc 100644
--- a/src/org/traccar/handler/events/IgnitionEventHandler.java
+++ b/src/org/traccar/handler/events/IgnitionEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
* Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.Map;
import io.netty.channel.ChannelHandler;
-import org.traccar.Context;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -28,10 +28,16 @@ import org.traccar.model.Position;
@ChannelHandler.Sharable
public class IgnitionEventHandler extends BaseEventHandler {
+ private final IdentityManager identityManager;
+
+ public IgnitionEventHandler(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
@Override
protected Map<Event, Position> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
- if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
+ Device device = identityManager.getById(position.getDeviceId());
+ if (device == null || !identityManager.isLatestPosition(position)) {
return null;
}
@@ -40,7 +46,7 @@ public class IgnitionEventHandler extends BaseEventHandler {
if (position.getAttributes().containsKey(Position.KEY_IGNITION)) {
boolean ignition = position.getBoolean(Position.KEY_IGNITION);
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ Position lastPosition = identityManager.getLastPosition(position.getDeviceId());
if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_IGNITION)) {
boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);