aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-09-29 17:57:22 -0700
committerAnton Tananaev <anton@traccar.org>2022-09-29 17:57:22 -0700
commit0a853f2aa3556554acd0b43a5008c43c345fa300 (patch)
treeafbcf9d7924ba44e9bd0b33654f1e1fee0ff1104 /src/main/java/org/traccar/database
parente7bd758824386e4f77f78ceca57675ef7934435a (diff)
downloadtrackermap-server-0a853f2aa3556554acd0b43a5008c43c345fa300.tar.gz
trackermap-server-0a853f2aa3556554acd0b43a5008c43c345fa300.tar.bz2
trackermap-server-0a853f2aa3556554acd0b43a5008c43c345fa300.zip
Synchronize queued commands
Diffstat (limited to 'src/main/java/org/traccar/database')
-rw-r--r--src/main/java/org/traccar/database/CommandsManager.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/database/CommandsManager.java b/src/main/java/org/traccar/database/CommandsManager.java
index d56b4d472..53040ad53 100644
--- a/src/main/java/org/traccar/database/CommandsManager.java
+++ b/src/main/java/org/traccar/database/CommandsManager.java
@@ -18,6 +18,8 @@ package org.traccar.database;
import org.traccar.BaseProtocol;
import org.traccar.ServerManager;
+import org.traccar.broadcast.BroadcastInterface;
+import org.traccar.broadcast.BroadcastService;
import org.traccar.model.Command;
import org.traccar.model.Device;
import org.traccar.model.Position;
@@ -40,21 +42,24 @@ import java.util.Collection;
import java.util.stream.Collectors;
@Singleton
-public class CommandsManager {
+public class CommandsManager implements BroadcastInterface {
private final Storage storage;
private final ServerManager serverManager;
private final SmsManager smsManager;
private final ConnectionManager connectionManager;
+ private final BroadcastService broadcastService;
@Inject
public CommandsManager(
Storage storage, ServerManager serverManager, @Nullable SmsManager smsManager,
- ConnectionManager connectionManager) {
+ ConnectionManager connectionManager, BroadcastService broadcastService) {
this.storage = storage;
this.serverManager = serverManager;
this.smsManager = smsManager;
this.connectionManager = connectionManager;
+ this.broadcastService = broadcastService;
+ broadcastService.registerListener(this);
}
public boolean sendCommand(Command command) throws Exception {
@@ -81,6 +86,7 @@ public class CommandsManager {
deviceSession.sendCommand(command);
} else {
storage.addObject(QueuedCommand.fromCommand(command), new Request(new Columns.Exclude("id")));
+ broadcastService.updateCommand(true, deviceId);
return false;
}
}
@@ -108,4 +114,16 @@ public class CommandsManager {
}
}
+ @Override
+ public void updateCommand(boolean local, long deviceId) {
+ if (!local) {
+ DeviceSession deviceSession = connectionManager.getDeviceSession(deviceId);
+ if (deviceSession != null && deviceSession.supportsLiveCommands()) {
+ for (Command command : readQueuedCommands(deviceId)) {
+ deviceSession.sendCommand(command);
+ }
+ }
+ }
+ }
+
}