aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 12:19:46 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 12:19:46 -0800
commit2af6e4cc6255f59acaa17e6763063b775d7ba1ea (patch)
treed95d2aeb584eb2c8c5709ea727e881aa1c4fc8cd /src
parent8018a9269789d532431ed455b82c3a67acdd0e50 (diff)
downloadtrackermap-server-2af6e4cc6255f59acaa17e6763063b775d7ba1ea.tar.gz
trackermap-server-2af6e4cc6255f59acaa17e6763063b775d7ba1ea.tar.bz2
trackermap-server-2af6e4cc6255f59acaa17e6763063b775d7ba1ea.zip
Refactor fuel drop manager
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java4
-rw-r--r--src/org/traccar/MainModule.java7
-rw-r--r--src/org/traccar/database/IdentityManager.java2
-rw-r--r--src/org/traccar/handler/events/FuelDropEventHandler.java18
4 files changed, 22 insertions, 9 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 0187e1d3f..5cadfb2a6 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 FuelDropEventHandler fuelDropEventHandler;
private MotionEventHandler motionEventHandler;
private GeofenceEventHandler geofenceEventHandler;
private AlertEventHandler alertEventHandler;
@@ -75,7 +74,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
}
if (eventsEnabled) {
- fuelDropEventHandler = new FuelDropEventHandler();
motionEventHandler = Context.getMotionEventHandler();
geofenceEventHandler = new GeofenceEventHandler();
alertEventHandler = new AlertEventHandler();
@@ -160,7 +158,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
pipeline,
Main.getInjector().getInstance(CommandResultEventHandler.class),
Main.getInjector().getInstance(OverspeedEventHandler.class),
- fuelDropEventHandler,
+ Main.getInjector().getInstance(FuelDropEventHandler.class),
motionEventHandler,
geofenceEventHandler,
alertEventHandler,
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index fe280d7a3..46af5670c 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -57,6 +57,7 @@ import org.traccar.handler.HemisphereHandler;
import org.traccar.handler.MotionHandler;
import org.traccar.handler.RemoteAddressHandler;
import org.traccar.handler.events.CommandResultEventHandler;
+import org.traccar.handler.events.FuelDropEventHandler;
import org.traccar.handler.events.OverspeedEventHandler;
import org.traccar.reports.model.TripsConfig;
@@ -291,6 +292,12 @@ public class MainModule extends AbstractModule {
return new OverspeedEventHandler(config, deviceManager, geofenceManager);
}
+ @Singleton
+ @Provides
+ public static FuelDropEventHandler provideFuelDropEventHandler(IdentityManager identityManager) {
+ return new FuelDropEventHandler(identityManager);
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
index 59d2f9362..6228a0f75 100644
--- a/src/org/traccar/database/IdentityManager.java
+++ b/src/org/traccar/database/IdentityManager.java
@@ -38,4 +38,6 @@ public interface IdentityManager {
long lookupAttributeLong(long deviceId, String attributeName, long defaultValue, boolean lookupConfig);
+ double lookupAttributeDouble(long deviceId, String attributeName, double defaultValue, boolean lookupConfig);
+
}
diff --git a/src/org/traccar/handler/events/FuelDropEventHandler.java b/src/org/traccar/handler/events/FuelDropEventHandler.java
index f13b8c7bb..59de61bba 100644
--- a/src/org/traccar/handler/events/FuelDropEventHandler.java
+++ b/src/org/traccar/handler/events/FuelDropEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package org.traccar.handler.events;
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;
@@ -29,22 +29,28 @@ public class FuelDropEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold";
+ private final IdentityManager identityManager;
+
+ public FuelDropEventHandler(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
@Override
protected Map<Event, Position> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
+ Device device = identityManager.getById(position.getDeviceId());
if (device == null) {
return null;
}
- if (!Context.getIdentityManager().isLatestPosition(position)) {
+ if (!identityManager.isLatestPosition(position)) {
return null;
}
- double fuelDropThreshold = Context.getDeviceManager()
+ double fuelDropThreshold = identityManager
.lookupAttributeDouble(device.getId(), ATTRIBUTE_FUEL_DROP_THRESHOLD, 0, false);
if (fuelDropThreshold > 0) {
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ Position lastPosition = identityManager.getLastPosition(position.getDeviceId());
if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)
&& lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {