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 | |
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')
-rw-r--r-- | src/main/java/org/traccar/BaseProtocolDecoder.java | 12 | ||||
-rw-r--r-- | src/main/java/org/traccar/database/CommandsManager.java | 14 | ||||
-rw-r--r-- | src/main/java/org/traccar/database/ConnectionManager.java | 4 |
3 files changed, 22 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index d014b0871..8981fe4c8 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -21,10 +21,12 @@ import io.netty.handler.codec.http.HttpRequestDecoder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.config.Config; +import org.traccar.database.CommandsManager; import org.traccar.database.ConnectionManager; import org.traccar.database.IdentityManager; import org.traccar.database.StatisticsManager; import org.traccar.helper.UnitsConverter; +import org.traccar.model.Command; import org.traccar.model.Device; import org.traccar.model.Position; @@ -245,6 +247,16 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { if (deviceId > 0) { connectionManager.updateDevice(deviceId, Device.STATUS_ONLINE, new Date()); } + sendQueuedCommands(channel, remoteAddress, deviceId); + } + + protected void sendQueuedCommands(Channel channel, SocketAddress remoteAddress, long deviceId) { + CommandsManager commandsManager = Context.getCommandsManager(); + if (commandsManager != null) { + for (Command command : commandsManager.readQueuedCommands(deviceId)) { + protocol.sendDataCommand(channel, remoteAddress, command); + } + } } @Override 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; } } diff --git a/src/main/java/org/traccar/database/ConnectionManager.java b/src/main/java/org/traccar/database/ConnectionManager.java index dd0071143..4d43bc71b 100644 --- a/src/main/java/org/traccar/database/ConnectionManager.java +++ b/src/main/java/org/traccar/database/ConnectionManager.java @@ -139,10 +139,6 @@ public class ConnectionManager { } updateDevice(device); - - if (status.equals(Device.STATUS_ONLINE) && !oldStatus.equals(Device.STATUS_ONLINE)) { - Context.getCommandsManager().sendQueuedCommands(getActiveDevice(deviceId)); - } } public Map<Event, Position> updateDeviceState(long deviceId) { |