aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 16:16:00 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 16:16:00 -0800
commit2a584c67a1663897d98e7c64fe161c88b30ef314 (patch)
tree008920bb182dc6ff622c88342b6fa9ca2a998335 /src
parentaddbd4b58d959a7996af7631dd3449ac779b027f (diff)
downloadtraccar-server-2a584c67a1663897d98e7c64fe161c88b30ef314.tar.gz
traccar-server-2a584c67a1663897d98e7c64fe161c88b30ef314.tar.bz2
traccar-server-2a584c67a1663897d98e7c64fe161c88b30ef314.zip
Refactor alert event handler
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/config/Keys.java6
-rw-r--r--src/org/traccar/handler/events/AlertEventHandler.java14
4 files changed, 23 insertions, 8 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 1bf8576ce..5e194c856 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 AlertEventHandler alertEventHandler;
private IgnitionEventHandler ignitionEventHandler;
private MaintenanceEventHandler maintenanceEventHandler;
private DriverEventHandler driverEventHandler;
@@ -72,7 +71,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
}
if (eventsEnabled) {
- alertEventHandler = new AlertEventHandler();
ignitionEventHandler = new IgnitionEventHandler();
maintenanceEventHandler = new MaintenanceEventHandler();
driverEventHandler = new DriverEventHandler();
@@ -157,7 +155,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
Main.getInjector().getInstance(FuelDropEventHandler.class),
Main.getInjector().getInstance(MotionEventHandler.class),
Main.getInjector().getInstance(GeofenceEventHandler.class),
- alertEventHandler,
+ Main.getInjector().getInstance(AlertEventHandler.class),
ignitionEventHandler,
maintenanceEventHandler,
driverEventHandler);
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index fd49fe3b5..3f196972f 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -57,6 +57,7 @@ import org.traccar.handler.GeolocationHandler;
import org.traccar.handler.HemisphereHandler;
import org.traccar.handler.MotionHandler;
import org.traccar.handler.RemoteAddressHandler;
+import org.traccar.handler.events.AlertEventHandler;
import org.traccar.handler.events.CommandResultEventHandler;
import org.traccar.handler.events.FuelDropEventHandler;
import org.traccar.handler.events.GeofenceEventHandler;
@@ -320,6 +321,12 @@ public class MainModule extends AbstractModule {
return new GeofenceEventHandler(identityManager, geofenceManager, calendarManager);
}
+ @Singleton
+ @Provides
+ public static AlertEventHandler provideAlertEventHandler(Config config, IdentityManager identityManager) {
+ return new AlertEventHandler(config, identityManager);
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/config/Keys.java b/src/org/traccar/config/Keys.java
index c7c5d16c6..48cf3e558 100644
--- a/src/org/traccar/config/Keys.java
+++ b/src/org/traccar/config/Keys.java
@@ -64,6 +64,12 @@ public final class Keys {
"event.overspeed.preferLowest", Boolean.class);
/**
+ * Do not generate alert event if same alert was present in last known location.
+ */
+ public static final ConfigKey EVENT_IGNORE_DUPLICATE_ALERTS = new ConfigKey(
+ "event.ignoreDuplicateAlerts", Boolean.class);
+
+ /**
* List of external handler classes to use in Netty pipeline.
*/
public static final ConfigKey EXTRA_HANDLERS = new ConfigKey(
diff --git a/src/org/traccar/handler/events/AlertEventHandler.java b/src/org/traccar/handler/events/AlertEventHandler.java
index 09a6e2b6b..0b7c8d23e 100644
--- a/src/org/traccar/handler/events/AlertEventHandler.java
+++ b/src/org/traccar/handler/events/AlertEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 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.
@@ -19,17 +19,21 @@ import java.util.Collections;
import java.util.Map;
import io.netty.channel.ChannelHandler;
-import org.traccar.Context;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Event;
import org.traccar.model.Position;
@ChannelHandler.Sharable
public class AlertEventHandler extends BaseEventHandler {
+ private final IdentityManager identityManager;
private final boolean ignoreDuplicateAlerts;
- public AlertEventHandler() {
- ignoreDuplicateAlerts = Context.getConfig().getBoolean("event.ignoreDuplicateAlerts");
+ public AlertEventHandler(Config config, IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ ignoreDuplicateAlerts = config.getBoolean(Keys.EVENT_IGNORE_DUPLICATE_ALERTS);
}
@Override
@@ -38,7 +42,7 @@ public class AlertEventHandler extends BaseEventHandler {
if (alarm != null) {
boolean ignoreAlert = false;
if (ignoreDuplicateAlerts) {
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ Position lastPosition = identityManager.getLastPosition(position.getDeviceId());
if (lastPosition != null && alarm.equals(lastPosition.getAttributes().get(Position.KEY_ALARM))) {
ignoreAlert = true;
}