aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 13:12:37 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 13:12:37 -0700
commitce661ec77a957b70c15509c6801e6f34b32ad11d (patch)
tree1fd501abc09e1eeceb3bf411b5d2612b27cc35ad /src/main/java/org/traccar/handler
parent154ff3b2175e67b3fac531cb9c5c5c68880f5e12 (diff)
downloadtrackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.gz
trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.bz2
trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.zip
Improve dependency injection
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/CopyAttributesHandler.java30
-rw-r--r--src/main/java/org/traccar/handler/DefaultDataHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/DistanceHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/EngineHoursHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java67
-rw-r--r--src/main/java/org/traccar/handler/HemisphereHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/MotionHandler.java12
-rw-r--r--src/main/java/org/traccar/handler/RemoteAddressHandler.java24
-rw-r--r--src/main/java/org/traccar/handler/SpeedLimitHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/TimeHandler.java14
-rw-r--r--src/main/java/org/traccar/handler/events/AlertEventHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/events/BehaviorEventHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/events/CommandResultEventHandler.java8
-rw-r--r--src/main/java/org/traccar/handler/events/DriverEventHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/events/FuelDropEventHandler.java4
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/events/IgnitionEventHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/events/MotionEventHandler.java5
-rw-r--r--src/main/java/org/traccar/handler/events/OverspeedEventHandler.java5
21 files changed, 155 insertions, 72 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
index 153da29b9..9dc170909 100644
--- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,6 +40,8 @@ import org.traccar.model.Attribute;
import org.traccar.model.Device;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class ComputedAttributesHandler extends BaseDataHandler {
@@ -52,6 +54,7 @@ public class ComputedAttributesHandler extends BaseDataHandler {
private final boolean includeDeviceAttributes;
+ @Inject
public ComputedAttributesHandler(
Config config, IdentityManager identityManager, AttributesManager attributesManager) {
this.identityManager = identityManager;
diff --git a/src/main/java/org/traccar/handler/CopyAttributesHandler.java b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
index f386116b0..8285dcc5d 100644
--- a/src/main/java/org/traccar/handler/CopyAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,27 +18,37 @@ package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import org.traccar.BaseDataHandler;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.database.IdentityManager;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class CopyAttributesHandler extends BaseDataHandler {
- private IdentityManager identityManager;
+ private final boolean enabled;
+ private final IdentityManager identityManager;
- public CopyAttributesHandler(IdentityManager identityManager) {
+ @Inject
+ public CopyAttributesHandler(Config config, IdentityManager identityManager) {
+ enabled = config.getBoolean(Keys.PROCESSING_COPY_ATTRIBUTES_ENABLE);
this.identityManager = identityManager;
}
@Override
protected Position handlePosition(Position position) {
- String attributesString = identityManager.lookupAttributeString(
- position.getDeviceId(), "processing.copyAttributes", "", false, true);
- Position last = identityManager.getLastPosition(position.getDeviceId());
- if (last != null) {
- for (String attribute : attributesString.split("[ ,]")) {
- if (last.getAttributes().containsKey(attribute) && !position.getAttributes().containsKey(attribute)) {
- position.getAttributes().put(attribute, last.getAttributes().get(attribute));
+ if (enabled) {
+ String attributesString = identityManager.lookupAttributeString(
+ position.getDeviceId(), "processing.copyAttributes", "", false, true);
+ Position last = identityManager.getLastPosition(position.getDeviceId());
+ if (last != null) {
+ for (String attribute : attributesString.split("[ ,]")) {
+ if (last.getAttributes().containsKey(attribute)
+ && !position.getAttributes().containsKey(attribute)) {
+ position.getAttributes().put(attribute, last.getAttributes().get(attribute));
+ }
}
}
}
diff --git a/src/main/java/org/traccar/handler/DefaultDataHandler.java b/src/main/java/org/traccar/handler/DefaultDataHandler.java
index 9d8ea044d..c2adfd799 100644
--- a/src/main/java/org/traccar/handler/DefaultDataHandler.java
+++ b/src/main/java/org/traccar/handler/DefaultDataHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 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.
@@ -22,6 +22,8 @@ import org.traccar.BaseDataHandler;
import org.traccar.database.DataManager;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class DefaultDataHandler extends BaseDataHandler {
@@ -29,6 +31,7 @@ public class DefaultDataHandler extends BaseDataHandler {
private final DataManager dataManager;
+ @Inject
public DefaultDataHandler(DataManager dataManager) {
this.dataManager = dataManager;
}
diff --git a/src/main/java/org/traccar/handler/DistanceHandler.java b/src/main/java/org/traccar/handler/DistanceHandler.java
index 1e7e444f6..08c8c068d 100644
--- a/src/main/java/org/traccar/handler/DistanceHandler.java
+++ b/src/main/java/org/traccar/handler/DistanceHandler.java
@@ -1,6 +1,6 @@
/*
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2015 Amila Silva
- * Copyright 2016 - 2021 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.
@@ -24,6 +24,7 @@ import org.traccar.database.IdentityManager;
import org.traccar.helper.DistanceCalculator;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -36,6 +37,7 @@ public class DistanceHandler extends BaseDataHandler {
private final int coordinatesMinError;
private final int coordinatesMaxError;
+ @Inject
public DistanceHandler(Config config, IdentityManager identityManager) {
this.identityManager = identityManager;
this.filter = config.getBoolean(Keys.COORDINATES_FILTER);
diff --git a/src/main/java/org/traccar/handler/EngineHoursHandler.java b/src/main/java/org/traccar/handler/EngineHoursHandler.java
index 92da84e6b..be2a46ade 100644
--- a/src/main/java/org/traccar/handler/EngineHoursHandler.java
+++ b/src/main/java/org/traccar/handler/EngineHoursHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,11 +21,14 @@ import org.traccar.BaseDataHandler;
import org.traccar.database.IdentityManager;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class EngineHoursHandler extends BaseDataHandler {
private final IdentityManager identityManager;
+ @Inject
public EngineHoursHandler(IdentityManager identityManager) {
this.identityManager = identityManager;
}
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index e576a26b8..0511ec98b 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2022 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,13 +19,15 @@ import io.netty.channel.ChannelHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.BaseDataHandler;
-import org.traccar.Context;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.database.DataManager;
+import org.traccar.database.IdentityManager;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import org.traccar.storage.StorageException;
+import javax.inject.Inject;
import java.util.Date;
@ChannelHandler.Sharable
@@ -33,21 +35,27 @@ public class FilterHandler extends BaseDataHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(FilterHandler.class);
- private boolean filterInvalid;
- private boolean filterZero;
- private boolean filterDuplicate;
- private long filterFuture;
- private boolean filterApproximate;
- private int filterAccuracy;
- private boolean filterStatic;
- private int filterDistance;
- private int filterMaxSpeed;
- private long filterMinPeriod;
- private boolean filterRelative;
- private long skipLimit;
- private boolean skipAttributes;
-
- public FilterHandler(Config config) {
+ private final boolean enabled;
+ private final boolean filterInvalid;
+ private final boolean filterZero;
+ private final boolean filterDuplicate;
+ private final long filterFuture;
+ private final boolean filterApproximate;
+ private final int filterAccuracy;
+ private final boolean filterStatic;
+ private final int filterDistance;
+ private final int filterMaxSpeed;
+ private final long filterMinPeriod;
+ private final boolean filterRelative;
+ private final long skipLimit;
+ private final boolean skipAttributes;
+
+ private final IdentityManager identityManager;
+ private final DataManager dataManager;
+
+ @Inject
+ public FilterHandler(Config config, IdentityManager identityManager, DataManager dataManager) {
+ enabled = config.getBoolean(Keys.FILTER_ENABLE);
filterInvalid = config.getBoolean(Keys.FILTER_INVALID);
filterZero = config.getBoolean(Keys.FILTER_ZERO);
filterDuplicate = config.getBoolean(Keys.FILTER_DUPLICATE);
@@ -57,10 +65,12 @@ public class FilterHandler extends BaseDataHandler {
filterStatic = config.getBoolean(Keys.FILTER_STATIC);
filterDistance = config.getInteger(Keys.FILTER_DISTANCE);
filterMaxSpeed = config.getInteger(Keys.FILTER_MAX_SPEED);
- filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000;
+ filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000L;
filterRelative = config.getBoolean(Keys.FILTER_RELATIVE);
skipLimit = config.getLong(Keys.FILTER_SKIP_LIMIT) * 1000;
skipAttributes = config.getBoolean(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE);
+ this.identityManager = identityManager;
+ this.dataManager = dataManager;
}
private boolean filterInvalid(Position position) {
@@ -134,7 +144,7 @@ public class FilterHandler extends BaseDataHandler {
private boolean skipAttributes(Position position) {
if (skipAttributes) {
- String attributesString = Context.getIdentityManager().lookupAttributeString(
+ String attributesString = identityManager.lookupAttributeString(
position.getDeviceId(), "filter.skipAttributes", "", false, true);
for (String attribute : attributesString.split("[ ,]")) {
if (position.getAttributes().containsKey(attribute)) {
@@ -173,7 +183,7 @@ public class FilterHandler extends BaseDataHandler {
if (filterRelative) {
try {
Date newFixTime = position.getFixTime();
- preceding = Context.getDataManager().getPrecedingPosition(deviceId, newFixTime);
+ preceding = dataManager.getPrecedingPosition(deviceId, newFixTime);
} catch (StorageException e) {
LOGGER.warn("Error retrieving preceding position; fallbacking to last received position.", e);
preceding = getLastReceivedPosition(deviceId);
@@ -199,14 +209,8 @@ public class FilterHandler extends BaseDataHandler {
}
if (filterType.length() > 0) {
-
- StringBuilder message = new StringBuilder();
- message.append("Position filtered by ");
- message.append(filterType.toString());
- message.append("filters from device: ");
- message.append(Context.getIdentityManager().getById(deviceId).getUniqueId());
-
- LOGGER.info(message.toString());
+ String uniqueId = identityManager.getById(deviceId).getUniqueId();
+ LOGGER.info("Position filtered by {}filters from device: {}", filterType, uniqueId);
return true;
}
@@ -214,15 +218,12 @@ public class FilterHandler extends BaseDataHandler {
}
private Position getLastReceivedPosition(long deviceId) {
- if (Context.getIdentityManager() != null) {
- return Context.getIdentityManager().getLastPosition(deviceId);
- }
- return null;
+ return identityManager.getLastPosition(deviceId);
}
@Override
protected Position handlePosition(Position position) {
- if (filter(position)) {
+ if (enabled && filter(position)) {
return null;
}
return position;
diff --git a/src/main/java/org/traccar/handler/HemisphereHandler.java b/src/main/java/org/traccar/handler/HemisphereHandler.java
index aff3d8a64..2e3ed9d91 100644
--- a/src/main/java/org/traccar/handler/HemisphereHandler.java
+++ b/src/main/java/org/traccar/handler/HemisphereHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 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.
@@ -21,12 +21,15 @@ import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class HemisphereHandler extends BaseDataHandler {
private int latitudeFactor;
private int longitudeFactor;
+ @Inject
public HemisphereHandler(Config config) {
String latitudeHemisphere = config.getString(Keys.LOCATION_LATITUDE_HEMISPHERE);
if (latitudeHemisphere != null) {
diff --git a/src/main/java/org/traccar/handler/MotionHandler.java b/src/main/java/org/traccar/handler/MotionHandler.java
index e8051dd75..864eb455d 100644
--- a/src/main/java/org/traccar/handler/MotionHandler.java
+++ b/src/main/java/org/traccar/handler/MotionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,14 +19,18 @@ package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import org.traccar.BaseDataHandler;
import org.traccar.model.Position;
+import org.traccar.reports.model.TripsConfig;
+
+import javax.inject.Inject;
@ChannelHandler.Sharable
public class MotionHandler extends BaseDataHandler {
- private double speedThreshold;
+ private final double speedThreshold;
- public MotionHandler(double speedThreshold) {
- this.speedThreshold = speedThreshold;
+ @Inject
+ public MotionHandler(TripsConfig tripsConfig) {
+ speedThreshold = tripsConfig.getSpeedThreshold();
}
@Override
diff --git a/src/main/java/org/traccar/handler/RemoteAddressHandler.java b/src/main/java/org/traccar/handler/RemoteAddressHandler.java
index c09b8c39a..809f67ca2 100644
--- a/src/main/java/org/traccar/handler/RemoteAddressHandler.java
+++ b/src/main/java/org/traccar/handler/RemoteAddressHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 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.
@@ -18,22 +18,34 @@ package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.net.InetSocketAddress;
@ChannelHandler.Sharable
public class RemoteAddressHandler extends ChannelInboundHandlerAdapter {
+ private final boolean enabled;
+
+ @Inject
+ public RemoteAddressHandler(Config config) {
+ enabled = config.getBoolean(Keys.PROCESSING_REMOTE_ADDRESS_ENABLE);
+ }
+
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
- InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
- String hostAddress = remoteAddress != null ? remoteAddress.getAddress().getHostAddress() : null;
+ if (enabled) {
+ InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
+ String hostAddress = remoteAddress != null ? remoteAddress.getAddress().getHostAddress() : null;
- if (msg instanceof Position) {
- Position position = (Position) msg;
- position.set(Position.KEY_IP, hostAddress);
+ if (msg instanceof Position) {
+ Position position = (Position) msg;
+ position.set(Position.KEY_IP, hostAddress);
+ }
}
ctx.fireChannelRead(msg);
diff --git a/src/main/java/org/traccar/handler/SpeedLimitHandler.java b/src/main/java/org/traccar/handler/SpeedLimitHandler.java
index 65f2c9cfe..0469b9f16 100644
--- a/src/main/java/org/traccar/handler/SpeedLimitHandler.java
+++ b/src/main/java/org/traccar/handler/SpeedLimitHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2020 - 2022 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.
@@ -23,6 +23,8 @@ import org.slf4j.LoggerFactory;
import org.traccar.model.Position;
import org.traccar.speedlimit.SpeedLimitProvider;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class SpeedLimitHandler extends ChannelInboundHandlerAdapter {
@@ -30,6 +32,7 @@ public class SpeedLimitHandler extends ChannelInboundHandlerAdapter {
private final SpeedLimitProvider speedLimitProvider;
+ @Inject
public SpeedLimitHandler(SpeedLimitProvider speedLimitProvider) {
this.speedLimitProvider = speedLimitProvider;
}
diff --git a/src/main/java/org/traccar/handler/TimeHandler.java b/src/main/java/org/traccar/handler/TimeHandler.java
index 822c22a0a..c7e5e6e5c 100644
--- a/src/main/java/org/traccar/handler/TimeHandler.java
+++ b/src/main/java/org/traccar/handler/TimeHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2022 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.
@@ -24,6 +24,7 @@ import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -31,11 +32,18 @@ import java.util.Set;
@ChannelHandler.Sharable
public class TimeHandler extends ChannelInboundHandlerAdapter {
+ private final boolean enabled;
private final boolean useServerTime;
private final Set<String> protocols;
+ @Inject
public TimeHandler(Config config) {
- useServerTime = config.getString(Keys.TIME_OVERRIDE).equalsIgnoreCase("serverTime");
+ enabled = config.hasKey(Keys.TIME_OVERRIDE);
+ if (enabled) {
+ useServerTime = config.getString(Keys.TIME_OVERRIDE).equalsIgnoreCase("serverTime");
+ } else {
+ useServerTime = false;
+ }
String protocolList = Context.getConfig().getString(Keys.TIME_PROTOCOLS);
if (protocolList != null) {
protocols = new HashSet<>(Arrays.asList(protocolList.split("[, ]")));
@@ -47,7 +55,7 @@ public class TimeHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
- if (msg instanceof Position && (protocols == null
+ if (enabled && msg instanceof Position && (protocols == null
|| protocols.contains(ctx.pipeline().get(BaseProtocolDecoder.class).getProtocolName()))) {
Position position = (Position) msg;
diff --git a/src/main/java/org/traccar/handler/events/AlertEventHandler.java b/src/main/java/org/traccar/handler/events/AlertEventHandler.java
index 05dbc516e..6e7b0b16e 100644
--- a/src/main/java/org/traccar/handler/events/AlertEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/AlertEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 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.
@@ -25,12 +25,15 @@ import org.traccar.database.IdentityManager;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class AlertEventHandler extends BaseEventHandler {
private final IdentityManager identityManager;
private final boolean ignoreDuplicateAlerts;
+ @Inject
public AlertEventHandler(Config config, IdentityManager identityManager) {
this.identityManager = identityManager;
ignoreDuplicateAlerts = config.getBoolean(Keys.EVENT_IGNORE_DUPLICATE_ALERTS);
diff --git a/src/main/java/org/traccar/handler/events/BehaviorEventHandler.java b/src/main/java/org/traccar/handler/events/BehaviorEventHandler.java
index 767cef3f6..bbf749cdc 100644
--- a/src/main/java/org/traccar/handler/events/BehaviorEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/BehaviorEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2021 - 2022 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.
@@ -23,6 +23,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.util.Collections;
import java.util.Map;
@@ -34,6 +35,7 @@ public class BehaviorEventHandler extends BaseEventHandler {
private final IdentityManager identityManager;
+ @Inject
public BehaviorEventHandler(Config config, IdentityManager identityManager) {
accelerationThreshold = config.getDouble(Keys.EVENT_BEHAVIOR_ACCELERATION_THRESHOLD);
brakingThreshold = config.getDouble(Keys.EVENT_BEHAVIOR_BRAKING_THRESHOLD);
diff --git a/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java b/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java
index 9b7ff554e..858f84e09 100644
--- a/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/CommandResultEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 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.
@@ -22,9 +22,15 @@ import io.netty.channel.ChannelHandler;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class CommandResultEventHandler extends BaseEventHandler {
+ @Inject
+ public CommandResultEventHandler() {
+ }
+
@Override
protected Map<Event, Position> analyzePosition(Position position) {
Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
diff --git a/src/main/java/org/traccar/handler/events/DriverEventHandler.java b/src/main/java/org/traccar/handler/events/DriverEventHandler.java
index 6fdf4246b..510ac3465 100644
--- a/src/main/java/org/traccar/handler/events/DriverEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/DriverEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,11 +24,14 @@ import org.traccar.database.IdentityManager;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class DriverEventHandler extends BaseEventHandler {
private final IdentityManager identityManager;
+ @Inject
public DriverEventHandler(IdentityManager identityManager) {
this.identityManager = identityManager;
}
diff --git a/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java b/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
index 343a17311..7849abff9 100644
--- a/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/FuelDropEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 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.
@@ -21,6 +21,7 @@ import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.util.Collections;
import java.util.Map;
@@ -31,6 +32,7 @@ public class FuelDropEventHandler extends BaseEventHandler {
private final IdentityManager identityManager;
+ @Inject
public FuelDropEventHandler(IdentityManager identityManager) {
this.identityManager = identityManager;
}
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
index dae0c891f..36df7aaf3 100644
--- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 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.
@@ -30,6 +30,8 @@ import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class GeofenceEventHandler extends BaseEventHandler {
@@ -38,6 +40,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
private final CalendarManager calendarManager;
private final ConnectionManager connectionManager;
+ @Inject
public GeofenceEventHandler(
IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager,
ConnectionManager connectionManager) {
diff --git a/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java b/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
index 69df9a46b..9887c9db6 100644
--- a/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/IgnitionEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,11 +25,14 @@ import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class IgnitionEventHandler extends BaseEventHandler {
private final IdentityManager identityManager;
+ @Inject
public IgnitionEventHandler(IdentityManager identityManager) {
this.identityManager = identityManager;
}
diff --git a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
index 0f960ad1f..5b9ce4316 100644
--- a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,12 +26,15 @@ import org.traccar.model.Event;
import org.traccar.model.Maintenance;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class MaintenanceEventHandler extends BaseEventHandler {
private final IdentityManager identityManager;
private final MaintenancesManager maintenancesManager;
+ @Inject
public MaintenanceEventHandler(IdentityManager identityManager, MaintenancesManager maintenancesManager) {
this.identityManager = identityManager;
this.maintenancesManager = maintenancesManager;
diff --git a/src/main/java/org/traccar/handler/events/MotionEventHandler.java b/src/main/java/org/traccar/handler/events/MotionEventHandler.java
index db276f32b..23a39d070 100644
--- a/src/main/java/org/traccar/handler/events/MotionEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/MotionEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,8 @@ import org.traccar.model.Position;
import org.traccar.reports.ReportUtils;
import org.traccar.reports.model.TripsConfig;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class MotionEventHandler extends BaseEventHandler {
@@ -36,6 +38,7 @@ public class MotionEventHandler extends BaseEventHandler {
private final DeviceManager deviceManager;
private final TripsConfig tripsConfig;
+ @Inject
public MotionEventHandler(IdentityManager identityManager, DeviceManager deviceManager, TripsConfig tripsConfig) {
this.identityManager = identityManager;
this.deviceManager = deviceManager;
diff --git a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
index 347ad9005..102003c3c 100644
--- a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,8 @@ import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class OverspeedEventHandler extends BaseEventHandler {
@@ -43,6 +45,7 @@ public class OverspeedEventHandler extends BaseEventHandler {
private final long minimalDuration;
private final boolean preferLowest;
+ @Inject
public OverspeedEventHandler(Config config, DeviceManager deviceManager, GeofenceManager geofenceManager) {
this.deviceManager = deviceManager;
this.geofenceManager = geofenceManager;