From 91da9fa8e53836e71c36609132c38797317ae9e1 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 20 Oct 2017 15:12:11 +0500 Subject: Reverted using Queue --- src/org/traccar/database/CommandsManager.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') 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 { - private final Map> deviceQueues = new ConcurrentHashMap<>(); + private final Map> deviceQueues = new ConcurrentHashMap<>(); public CommandsManager(DataManager dataManager) { super(dataManager, Command.class); @@ -125,18 +127,20 @@ public class CommandsManager extends ExtendedObjectManager { return result; } - private List getDeviceQueue(long deviceId) { + private Queue getDeviceQueue(long deviceId) { if (!deviceQueues.containsKey(deviceId)) { - deviceQueues.put(deviceId, new ArrayList()); + deviceQueues.put(deviceId, new ConcurrentLinkedQueue()); } return deviceQueues.get(deviceId); } public void sendQueuedCommands(ActiveDevice activeDevice) { - List deviceQueue = deviceQueues.get(activeDevice.getDeviceId()); + Queue 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(); } } } -- cgit v1.2.3