diff options
author | Abyss777 <abyss@fox5.ru> | 2017-10-20 15:12:11 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-10-20 15:12:11 +0500 |
commit | 91da9fa8e53836e71c36609132c38797317ae9e1 (patch) | |
tree | 58121811c5ed26be60e4a8c2c4c45fbc50f40f26 /src/org/traccar/database | |
parent | 39be24a58767c05cb7001e77db1bae56cdbe4445 (diff) | |
download | trackermap-server-91da9fa8e53836e71c36609132c38797317ae9e1.tar.gz trackermap-server-91da9fa8e53836e71c36609132c38797317ae9e1.tar.bz2 trackermap-server-91da9fa8e53836e71c36609132c38797317ae9e1.zip |
Reverted using Queue
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/CommandsManager.java | 14 |
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(); } } } |