aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/events
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-09 07:00:20 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-09 07:00:20 -0700
commit12fe28bebbdbc61214363a9c7b51bd300ed62c15 (patch)
tree5e014f785a6f5856c24197b611fd108403bbd5e7 /src/main/java/org/traccar/handler/events
parentc4ff983ffe9a03a57d3ab0596abe8bce08c1ae2e (diff)
downloadtrackermap-server-12fe28bebbdbc61214363a9c7b51bd300ed62c15.tar.gz
trackermap-server-12fe28bebbdbc61214363a9c7b51bd300ed62c15.tar.bz2
trackermap-server-12fe28bebbdbc61214363a9c7b51bd300ed62c15.zip
Remove geofence manager
Diffstat (limited to 'src/main/java/org/traccar/handler/events')
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java34
-rw-r--r--src/main/java/org/traccar/handler/events/OverspeedEventHandler.java12
2 files changed, 20 insertions, 26 deletions
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
index 17e240f68..724f8f0d0 100644
--- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
@@ -15,52 +15,46 @@
*/
package org.traccar.handler.events;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import io.netty.channel.ChannelHandler;
-import org.traccar.session.ConnectionManager;
-import org.traccar.database.GeofenceManager;
-import org.traccar.database.IdentityManager;
+import org.traccar.helper.model.GeofenceUtil;
+import org.traccar.helper.model.PositionUtil;
import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Event;
+import org.traccar.model.Geofence;
import org.traccar.model.Position;
+import org.traccar.session.ConnectionManager;
import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
@ChannelHandler.Sharable
public class GeofenceEventHandler extends BaseEventHandler {
private final CacheManager cacheManager;
- private final IdentityManager identityManager;
- private final GeofenceManager geofenceManager;
private final ConnectionManager connectionManager;
@Inject
- public GeofenceEventHandler(
- CacheManager cacheManager, IdentityManager identityManager, GeofenceManager geofenceManager,
- ConnectionManager connectionManager) {
+ public GeofenceEventHandler(CacheManager cacheManager, ConnectionManager connectionManager) {
this.cacheManager = cacheManager;
- this.identityManager = identityManager;
- this.geofenceManager = geofenceManager;
this.connectionManager = connectionManager;
}
@Override
protected Map<Event, Position> analyzePosition(Position position) {
- Device device = identityManager.getById(position.getDeviceId());
+ Device device = cacheManager.getObject(Device.class, position.getDeviceId());
if (device == null) {
return null;
}
- if (!identityManager.isLatestPosition(position) || !position.getValid()) {
+ if (!PositionUtil.isLatest(cacheManager, position) || !position.getValid()) {
return null;
}
- List<Long> currentGeofences = geofenceManager.getCurrentDeviceGeofences(position);
+ List<Long> currentGeofences = GeofenceUtil.getCurrentGeofences(cacheManager, position);
List<Long> oldGeofences = new ArrayList<>();
if (device.getGeofenceIds() != null) {
oldGeofences.addAll(device.getGeofenceIds());
@@ -76,7 +70,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
Map<Event, Position> events = new HashMap<>();
for (long geofenceId : oldGeofences) {
- long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
+ long calendarId = cacheManager.getObject(Geofence.class, geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position);
@@ -85,7 +79,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
}
}
for (long geofenceId : newGeofences) {
- long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
+ long calendarId = cacheManager.getObject(Geofence.class, geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position);
diff --git a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
index 84d80e55f..45bb13be5 100644
--- a/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/OverspeedEventHandler.java
@@ -23,12 +23,12 @@ import io.netty.channel.ChannelHandler;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.DeviceManager;
-import org.traccar.database.GeofenceManager;
import org.traccar.model.Device;
import org.traccar.session.DeviceState;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Position;
+import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
@@ -39,16 +39,16 @@ public class OverspeedEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit";
private final DeviceManager deviceManager;
- private final GeofenceManager geofenceManager;
+ private final CacheManager cacheManager;
private final boolean notRepeat;
private final long minimalDuration;
private final boolean preferLowest;
@Inject
- public OverspeedEventHandler(Config config, DeviceManager deviceManager, GeofenceManager geofenceManager) {
+ public OverspeedEventHandler(Config config, DeviceManager deviceManager, CacheManager cacheManager) {
this.deviceManager = deviceManager;
- this.geofenceManager = geofenceManager;
+ this.cacheManager = cacheManager;
notRepeat = config.getBoolean(Keys.EVENT_OVERSPEED_NOT_REPEAT);
minimalDuration = config.getLong(Keys.EVENT_OVERSPEED_MINIMAL_DURATION) * 1000;
preferLowest = config.getBoolean(Keys.EVENT_OVERSPEED_PREFER_LOWEST);
@@ -133,9 +133,9 @@ public class OverspeedEventHandler extends BaseEventHandler {
double geofenceSpeedLimit = 0;
long overspeedGeofenceId = 0;
- if (geofenceManager != null && device.getGeofenceIds() != null) {
+ if (device.getGeofenceIds() != null) {
for (long geofenceId : device.getGeofenceIds()) {
- Geofence geofence = geofenceManager.getById(geofenceId);
+ Geofence geofence = cacheManager.getObject(Geofence.class, geofenceId);
if (geofence != null) {
double currentSpeedLimit = geofence.getDouble(ATTRIBUTE_SPEED_LIMIT);
if (currentSpeedLimit > 0 && geofenceSpeedLimit == 0