aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java4
-rw-r--r--src/org/traccar/MainModule.java14
-rw-r--r--src/org/traccar/handler/events/GeofenceEventHandler.java25
3 files changed, 31 insertions, 12 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index d0136a6bb..1bf8576ce 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 GeofenceEventHandler geofenceEventHandler;
private AlertEventHandler alertEventHandler;
private IgnitionEventHandler ignitionEventHandler;
private MaintenanceEventHandler maintenanceEventHandler;
@@ -73,7 +72,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
}
if (eventsEnabled) {
- geofenceEventHandler = new GeofenceEventHandler();
alertEventHandler = new AlertEventHandler();
ignitionEventHandler = new IgnitionEventHandler();
maintenanceEventHandler = new MaintenanceEventHandler();
@@ -158,7 +156,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
Main.getInjector().getInstance(OverspeedEventHandler.class),
Main.getInjector().getInstance(FuelDropEventHandler.class),
Main.getInjector().getInstance(MotionEventHandler.class),
- geofenceEventHandler,
+ Main.getInjector().getInstance(GeofenceEventHandler.class),
alertEventHandler,
ignitionEventHandler,
maintenanceEventHandler,
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index 10d35f72f..fd49fe3b5 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -22,6 +22,7 @@ import com.google.inject.Singleton;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.AttributesManager;
+import org.traccar.database.CalendarManager;
import org.traccar.database.DataManager;
import org.traccar.database.DeviceManager;
import org.traccar.database.GeofenceManager;
@@ -58,6 +59,7 @@ 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.GeofenceEventHandler;
import org.traccar.handler.events.MotionEventHandler;
import org.traccar.handler.events.OverspeedEventHandler;
import org.traccar.reports.model.TripsConfig;
@@ -108,6 +110,11 @@ public class MainModule extends AbstractModule {
}
@Provides
+ public static CalendarManager provideCalendarManager() {
+ return Context.getCalendarManager();
+ }
+
+ @Provides
public static AttributesManager provideAttributesManager() {
return Context.getAttributesManager();
}
@@ -306,6 +313,13 @@ public class MainModule extends AbstractModule {
return new MotionEventHandler(identityManager, deviceManager, tripsConfig);
}
+ @Singleton
+ @Provides
+ public static GeofenceEventHandler provideGeofenceEventHandler(
+ IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager) {
+ return new GeofenceEventHandler(identityManager, geofenceManager, calendarManager);
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/handler/events/GeofenceEventHandler.java b/src/org/traccar/handler/events/GeofenceEventHandler.java
index 878331c84..067c97957 100644
--- a/src/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/org/traccar/handler/events/GeofenceEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 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.
@@ -21,8 +21,9 @@ import java.util.List;
import java.util.Map;
import io.netty.channel.ChannelHandler;
-import org.traccar.Context;
+import org.traccar.database.CalendarManager;
import org.traccar.database.GeofenceManager;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Event;
@@ -31,19 +32,24 @@ import org.traccar.model.Position;
@ChannelHandler.Sharable
public class GeofenceEventHandler extends BaseEventHandler {
- private GeofenceManager geofenceManager;
+ private final IdentityManager identityManager;
+ private final GeofenceManager geofenceManager;
+ private final CalendarManager calendarManager;
- public GeofenceEventHandler() {
- geofenceManager = Context.getGeofenceManager();
+ public GeofenceEventHandler(
+ IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager) {
+ this.identityManager = identityManager;
+ this.geofenceManager = geofenceManager;
+ this.calendarManager = calendarManager;
}
@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) || !position.getValid()) {
+ if (!identityManager.isLatestPosition(position) || !position.getValid()) {
return null;
}
@@ -61,7 +67,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
Map<Event, Position> events = new HashMap<>();
for (long geofenceId : oldGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
+ Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
@@ -70,7 +76,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
}
for (long geofenceId : newGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
+ Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
@@ -79,4 +85,5 @@ public class GeofenceEventHandler extends BaseEventHandler {
}
return events;
}
+
}