From 65a39217ea14ef266a042c284189ac13a43b20c5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 16 Jun 2020 23:31:51 -0700 Subject: Improve shared connection active device hadling --- src/main/java/org/traccar/BaseProtocolDecoder.java | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index 8981fe4c8..99f3bc627 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -35,7 +35,9 @@ import java.net.SocketAddress; import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.TimeZone; public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { @@ -224,30 +226,27 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { if (statisticsManager != null) { statisticsManager.registerMessageReceived(); } - Position position = null; + Set deviceIds = new HashSet<>(); if (decodedMessage != null) { if (decodedMessage instanceof Position) { - position = (Position) decodedMessage; + deviceIds.add(((Position) decodedMessage).getDeviceId()); } else if (decodedMessage instanceof Collection) { Collection positions = (Collection) decodedMessage; - if (!positions.isEmpty()) { - position = positions.iterator().next(); + for (Position position : positions) { + deviceIds.add(position.getDeviceId()); } } } - long deviceId = 0; - if (position != null) { - deviceId = position.getDeviceId(); - } else { + if (deviceIds.isEmpty()) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession != null) { - deviceId = deviceSession.getDeviceId(); + deviceIds.add(deviceSession.getDeviceId()); } } - if (deviceId > 0) { + for (long deviceId : deviceIds) { connectionManager.updateDevice(deviceId, Device.STATUS_ONLINE, new Date()); + sendQueuedCommands(channel, remoteAddress, deviceId); } - sendQueuedCommands(channel, remoteAddress, deviceId); } protected void sendQueuedCommands(Channel channel, SocketAddress remoteAddress, long deviceId) { -- cgit v1.2.3