aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-06-16 23:31:51 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-06-16 23:31:51 -0700
commit65a39217ea14ef266a042c284189ac13a43b20c5 (patch)
tree548d3252d67e3e082e4b8fa957d8704af79b71fc /src/main/java/org
parent18d86933c465f87e028e9f065c973cf390a2578b (diff)
downloadtraccar-server-65a39217ea14ef266a042c284189ac13a43b20c5.tar.gz
traccar-server-65a39217ea14ef266a042c284189ac13a43b20c5.tar.bz2
traccar-server-65a39217ea14ef266a042c284189ac13a43b20c5.zip
Improve shared connection active device hadling
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/BaseProtocolDecoder.java21
1 files changed, 10 insertions, 11 deletions
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<Long> deviceIds = new HashSet<>();
if (decodedMessage != null) {
if (decodedMessage instanceof Position) {
- position = (Position) decodedMessage;
+ deviceIds.add(((Position) decodedMessage).getDeviceId());
} else if (decodedMessage instanceof Collection) {
Collection<Position> 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) {