aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/database/CommandsManager.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/org/traccar/database/CommandsManager.java b/src/org/traccar/database/CommandsManager.java
index f9feb927d..cae4ac6f7 100644
--- a/src/org/traccar/database/CommandsManager.java
+++ b/src/org/traccar/database/CommandsManager.java
@@ -22,7 +22,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
import org.traccar.BaseProtocol;
import org.traccar.Context;
@@ -33,7 +35,7 @@ import org.traccar.model.Position;
public class CommandsManager extends ExtendedObjectManager<Command> {
- private final Map<Long, List<Command>> deviceQueues = new ConcurrentHashMap<>();
+ private final Map<Long, Queue<Command>> deviceQueues = new ConcurrentHashMap<>();
public CommandsManager(DataManager dataManager) {
super(dataManager, Command.class);
@@ -125,18 +127,20 @@ public class CommandsManager extends ExtendedObjectManager<Command> {
return result;
}
- private List<Command> getDeviceQueue(long deviceId) {
+ private Queue<Command> getDeviceQueue(long deviceId) {
if (!deviceQueues.containsKey(deviceId)) {
- deviceQueues.put(deviceId, new ArrayList<Command>());
+ deviceQueues.put(deviceId, new ConcurrentLinkedQueue<Command>());
}
return deviceQueues.get(deviceId);
}
public void sendQueuedCommands(ActiveDevice activeDevice) {
- List<Command> deviceQueue = deviceQueues.get(activeDevice.getDeviceId());
+ Queue<Command> deviceQueue = deviceQueues.get(activeDevice.getDeviceId());
if (deviceQueue != null) {
- for (Command command : deviceQueue) {
+ Command command = deviceQueue.poll();
+ while (command != null) {
activeDevice.sendCommand(command);
+ command = deviceQueue.poll();
}
}
}