aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-07-18 20:47:11 -0700
committerAnton Tananaev <anton@traccar.org>2022-07-18 20:47:11 -0700
commitc4509720c5dab9d7ba17dd6e89f0d846052b0c39 (patch)
tree73a14316d484ac6ed5137f44f1532350cee5382f
parenta61e08cb47b8294bf639ebdc0916ead031e92827 (diff)
downloadtrackermap-server-c4509720c5dab9d7ba17dd6e89f0d846052b0c39.tar.gz
trackermap-server-c4509720c5dab9d7ba17dd6e89f0d846052b0c39.tar.bz2
trackermap-server-c4509720c5dab9d7ba17dd6e89f0d846052b0c39.zip
Reset start on restart
-rw-r--r--src/main/java/org/traccar/Main.java6
-rw-r--r--src/main/java/org/traccar/broadcast/BroadcastService.java1
-rw-r--r--src/main/java/org/traccar/broadcast/MulticastBroadcastService.java5
-rw-r--r--src/main/java/org/traccar/broadcast/NullBroadcastService.java5
-rw-r--r--src/main/java/org/traccar/helper/model/DeviceUtil.java33
5 files changed, 50 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java
index 6a968ac7e..e34fbb72a 100644
--- a/src/main/java/org/traccar/Main.java
+++ b/src/main/java/org/traccar/Main.java
@@ -20,8 +20,10 @@ import com.google.inject.Injector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.broadcast.BroadcastService;
+import org.traccar.helper.model.DeviceUtil;
import org.traccar.schedule.ScheduleManager;
import org.traccar.storage.DatabaseModule;
+import org.traccar.storage.Storage;
import org.traccar.web.WebModule;
import org.traccar.web.WebServer;
@@ -120,6 +122,10 @@ public final class Main {
LOGGER.info("Version: " + Main.class.getPackage().getImplementationVersion());
LOGGER.info("Starting server...");
+ if (injector.getInstance(BroadcastService.class).singleInstance()) {
+ DeviceUtil.resetStatus(injector.getInstance(Storage.class));
+ }
+
var services = Stream.of(
ServerManager.class, WebServer.class, ScheduleManager.class, BroadcastService.class)
.map(injector::getInstance)
diff --git a/src/main/java/org/traccar/broadcast/BroadcastService.java b/src/main/java/org/traccar/broadcast/BroadcastService.java
index 8a2e4bafc..a86c43b5b 100644
--- a/src/main/java/org/traccar/broadcast/BroadcastService.java
+++ b/src/main/java/org/traccar/broadcast/BroadcastService.java
@@ -18,5 +18,6 @@ package org.traccar.broadcast;
import org.traccar.LifecycleObject;
public interface BroadcastService extends LifecycleObject, BroadcastInterface {
+ boolean singleInstance();
void registerListener(BroadcastInterface listener);
}
diff --git a/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java b/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java
index 3eafe07d3..be65b7826 100644
--- a/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java
+++ b/src/main/java/org/traccar/broadcast/MulticastBroadcastService.java
@@ -71,6 +71,11 @@ public class MulticastBroadcastService implements BroadcastService {
}
@Override
+ public boolean singleInstance() {
+ return false;
+ }
+
+ @Override
public void registerListener(BroadcastInterface listener) {
listeners.add(listener);
}
diff --git a/src/main/java/org/traccar/broadcast/NullBroadcastService.java b/src/main/java/org/traccar/broadcast/NullBroadcastService.java
index 3f41299db..f95037990 100644
--- a/src/main/java/org/traccar/broadcast/NullBroadcastService.java
+++ b/src/main/java/org/traccar/broadcast/NullBroadcastService.java
@@ -18,6 +18,11 @@ package org.traccar.broadcast;
public class NullBroadcastService implements BroadcastService {
@Override
+ public boolean singleInstance() {
+ return true;
+ }
+
+ @Override
public void registerListener(BroadcastInterface listener) {
}
diff --git a/src/main/java/org/traccar/helper/model/DeviceUtil.java b/src/main/java/org/traccar/helper/model/DeviceUtil.java
new file mode 100644
index 000000000..597078caf
--- /dev/null
+++ b/src/main/java/org/traccar/helper/model/DeviceUtil.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 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.
+ * 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.helper.model;
+
+import org.traccar.model.Device;
+import org.traccar.storage.Storage;
+import org.traccar.storage.StorageException;
+import org.traccar.storage.query.Columns;
+import org.traccar.storage.query.Request;
+
+public final class DeviceUtil {
+
+ private DeviceUtil() {
+ }
+
+ public static void resetStatus(Storage storage) throws StorageException {
+ storage.updateObject(new Device(), new Request(new Columns.Include("status")));
+ }
+
+}