aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/schedule
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/schedule')
-rw-r--r--src/main/java/org/traccar/schedule/ScheduleManager.java14
-rw-r--r--src/main/java/org/traccar/schedule/ScheduleTask.java7
-rw-r--r--src/main/java/org/traccar/schedule/SingleScheduleTask.java23
-rw-r--r--src/main/java/org/traccar/schedule/TaskDeleteTemporary.java2
-rw-r--r--src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java2
-rw-r--r--src/main/java/org/traccar/schedule/TaskExpirations.java2
-rw-r--r--src/main/java/org/traccar/schedule/TaskReports.java2
7 files changed, 45 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/schedule/ScheduleManager.java b/src/main/java/org/traccar/schedule/ScheduleManager.java
index 742428fd8..fd8171148 100644
--- a/src/main/java/org/traccar/schedule/ScheduleManager.java
+++ b/src/main/java/org/traccar/schedule/ScheduleManager.java
@@ -20,6 +20,9 @@ import org.traccar.LifecycleObject;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
+
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.stream.Stream;
@@ -28,11 +31,13 @@ import java.util.stream.Stream;
public class ScheduleManager implements LifecycleObject {
private final Injector injector;
+ private final boolean secondary;
private ScheduledExecutorService executor;
@Inject
- public ScheduleManager(Injector injector) {
+ public ScheduleManager(Injector injector, Config config) {
this.injector = injector;
+ secondary = config.getBoolean(Keys.BROADCAST_SECONDARY);
}
@Override
@@ -46,7 +51,12 @@ public class ScheduleManager implements LifecycleObject {
TaskReports.class,
TaskDeviceInactivityCheck.class,
TaskWebSocketKeepalive.class)
- .forEachOrdered(task -> injector.getInstance(task).schedule(executor));
+ .forEachOrdered(taskClass -> {
+ var task = injector.getInstance(taskClass);
+ if (task.multipleInstances() || !secondary) {
+ task.schedule(executor);
+ }
+ });
}
@Override
diff --git a/src/main/java/org/traccar/schedule/ScheduleTask.java b/src/main/java/org/traccar/schedule/ScheduleTask.java
index 1b537213b..a2a31ac4f 100644
--- a/src/main/java/org/traccar/schedule/ScheduleTask.java
+++ b/src/main/java/org/traccar/schedule/ScheduleTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 - 2024 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,5 +18,10 @@ package org.traccar.schedule;
import java.util.concurrent.ScheduledExecutorService;
public interface ScheduleTask extends Runnable {
+
+ default boolean multipleInstances() {
+ return true;
+ }
+
void schedule(ScheduledExecutorService executor);
}
diff --git a/src/main/java/org/traccar/schedule/SingleScheduleTask.java b/src/main/java/org/traccar/schedule/SingleScheduleTask.java
new file mode 100644
index 000000000..a0f1deee4
--- /dev/null
+++ b/src/main/java/org/traccar/schedule/SingleScheduleTask.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2024 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.schedule;
+
+public abstract class SingleScheduleTask implements ScheduleTask {
+ @Override
+ public boolean multipleInstances() {
+ return false;
+ }
+}
diff --git a/src/main/java/org/traccar/schedule/TaskDeleteTemporary.java b/src/main/java/org/traccar/schedule/TaskDeleteTemporary.java
index 0cead59fb..eb49b7e46 100644
--- a/src/main/java/org/traccar/schedule/TaskDeleteTemporary.java
+++ b/src/main/java/org/traccar/schedule/TaskDeleteTemporary.java
@@ -28,7 +28,7 @@ import java.util.Date;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-public class TaskDeleteTemporary implements ScheduleTask {
+public class TaskDeleteTemporary extends SingleScheduleTask {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskDeleteTemporary.class);
diff --git a/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java b/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
index 8e45568d5..9bc98d8d3 100644
--- a/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
+++ b/src/main/java/org/traccar/schedule/TaskDeviceInactivityCheck.java
@@ -34,7 +34,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-public class TaskDeviceInactivityCheck implements ScheduleTask {
+public class TaskDeviceInactivityCheck extends SingleScheduleTask {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskDeviceInactivityCheck.class);
diff --git a/src/main/java/org/traccar/schedule/TaskExpirations.java b/src/main/java/org/traccar/schedule/TaskExpirations.java
index e16dcd86c..03be0c97f 100644
--- a/src/main/java/org/traccar/schedule/TaskExpirations.java
+++ b/src/main/java/org/traccar/schedule/TaskExpirations.java
@@ -36,7 +36,7 @@ import org.traccar.storage.query.Request;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-public class TaskExpirations implements ScheduleTask {
+public class TaskExpirations extends SingleScheduleTask {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskExpirations.class);
diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java
index c57158cb9..1b9b15749 100644
--- a/src/main/java/org/traccar/schedule/TaskReports.java
+++ b/src/main/java/org/traccar/schedule/TaskReports.java
@@ -50,7 +50,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-public class TaskReports implements ScheduleTask {
+public class TaskReports extends SingleScheduleTask {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskReports.class);