aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-11 15:04:51 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-11 15:04:51 -0700
commit7c08991f12b4958135fdffc26f272677c03630ad (patch)
treec1111ec78bad1dd8b0e4eb8f0c9194095d154d57 /src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
parent4025a42c42e34bb620f4263de05781a10ddc7a9d (diff)
downloadtrackermap-server-7c08991f12b4958135fdffc26f272677c03630ad.tar.gz
trackermap-server-7c08991f12b4958135fdffc26f272677c03630ad.tar.bz2
trackermap-server-7c08991f12b4958135fdffc26f272677c03630ad.zip
Inject network client
Diffstat (limited to 'src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java')
-rw-r--r--src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java b/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
index 80641d7d4..f2ed3c3b3 100644
--- a/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
+++ b/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.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.
@@ -15,17 +15,19 @@
*/
package org.traccar.schedule;
-import org.traccar.Context;
+import org.traccar.database.DeviceManager;
+import org.traccar.database.NotificationManager;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-public class TaskDeviceInactivityCheck implements Runnable {
+public class TaskDeviceInactivityCheck implements ScheduleTask {
public static final String ATTRIBUTE_DEVICE_INACTIVITY_START = "deviceInactivityStart";
public static final String ATTRIBUTE_DEVICE_INACTIVITY_PERIOD = "deviceInactivityPeriod";
@@ -33,6 +35,16 @@ public class TaskDeviceInactivityCheck implements Runnable {
private static final long CHECK_PERIOD_MINUTES = 15;
+ private final DeviceManager deviceManager;
+ private final NotificationManager notificationManager;
+
+ @Inject
+ public TaskDeviceInactivityCheck(DeviceManager deviceManager, NotificationManager notificationManager) {
+ this.deviceManager = deviceManager;
+ this.notificationManager = notificationManager;
+ }
+
+ @Override
public void schedule(ScheduledExecutorService executor) {
executor.scheduleAtFixedRate(this, CHECK_PERIOD_MINUTES, CHECK_PERIOD_MINUTES, TimeUnit.MINUTES);
}
@@ -43,7 +55,7 @@ public class TaskDeviceInactivityCheck implements Runnable {
long checkPeriod = TimeUnit.MINUTES.toMillis(CHECK_PERIOD_MINUTES);
Map<Event, Position> events = new HashMap<>();
- for (Device device : Context.getDeviceManager().getAllDevices()) {
+ for (Device device : deviceManager.getAllDevices()) {
if (device.getLastUpdate() != null && checkDevice(device, currentTime, checkPeriod)) {
Event event = new Event(Event.TYPE_DEVICE_INACTIVE, device.getId());
event.set(ATTRIBUTE_LAST_UPDATE, device.getLastUpdate().getTime());
@@ -51,7 +63,7 @@ public class TaskDeviceInactivityCheck implements Runnable {
}
}
- Context.getNotificationManager().updateEvents(events);
+ notificationManager.updateEvents(events);
}
private boolean checkDevice(Device device, long currentTime, long checkPeriod) {