diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-15 15:58:52 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-03-15 15:58:52 -0700 |
commit | 11dcacc2fdfd29f4440c8c46e501ef565f9b1dfd (patch) | |
tree | ad4aff5cb82af52d35e961de6ed69d8914b5e17a /src/main/java/org/traccar/database/CommandsManager.java | |
parent | 6adcd4a8dd950a5f945c818280974a0302c9fd8b (diff) | |
download | trackermap-server-11dcacc2fdfd29f4440c8c46e501ef565f9b1dfd.tar.gz trackermap-server-11dcacc2fdfd29f4440c8c46e501ef565f9b1dfd.tar.bz2 trackermap-server-11dcacc2fdfd29f4440c8c46e501ef565f9b1dfd.zip |
Decoder to send queued commands
Diffstat (limited to 'src/main/java/org/traccar/database/CommandsManager.java')
-rw-r--r-- | src/main/java/org/traccar/database/CommandsManager.java | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/database/CommandsManager.java b/src/main/java/org/traccar/database/CommandsManager.java index de6eeeba8..99114db5e 100644 --- a/src/main/java/org/traccar/database/CommandsManager.java +++ b/src/main/java/org/traccar/database/CommandsManager.java @@ -161,21 +161,27 @@ public class CommandsManager extends ExtendedObjectManager<Command> { } } - public void sendQueuedCommands(ActiveDevice activeDevice) { + public Collection<Command> readQueuedCommands(long deviceId) { + return readQueuedCommands(deviceId, Integer.MAX_VALUE); + } + + public Collection<Command> readQueuedCommands(long deviceId, int count) { Queue<Command> deviceQueue; try { readLock(); - deviceQueue = deviceQueues.get(activeDevice.getDeviceId()); + deviceQueue = deviceQueues.get(deviceId); } finally { readUnlock(); } + Collection<Command> result = new ArrayList<>(); if (deviceQueue != null) { Command command = deviceQueue.poll(); - while (command != null) { - activeDevice.sendCommand(command); + while (command != null && result.size() < count) { + result.add(command); command = deviceQueue.poll(); } } + return result; } } |