aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database/CommandsManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/database/CommandsManager.java')
-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);
+ }
+ }
+ }
+ }
+
}