aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-15 02:47:53 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-12-15 10:49:11 +1300
commit197510809bd2b59f3d13a8f36626cec2dfe25cb6 (patch)
tree9d3d51930750ad436fb9b1ae322d38ca6f9b7cc9 /src/org/traccar/BaseProtocolDecoder.java
parentd2119238ae75b7a6cf462c223b6017d3b37909ad (diff)
downloadtrackermap-server-197510809bd2b59f3d13a8f36626cec2dfe25cb6.tar.gz
trackermap-server-197510809bd2b59f3d13a8f36626cec2dfe25cb6.tar.bz2
trackermap-server-197510809bd2b59f3d13a8f36626cec2dfe25cb6.zip
Reuse deviceId from position (fix #2660)
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index ea0905bf2..5063174ce 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -23,6 +23,7 @@ import org.traccar.model.Position;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -165,13 +166,29 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
@Override
- protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) {
+ protected void onMessageEvent(
+ Channel channel, SocketAddress remoteAddress, Object originalMessage, Object decodedMessage) {
if (Context.getStatisticsManager() != null) {
Context.getStatisticsManager().registerMessageReceived();
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession != null) {
- Context.getConnectionManager().updateDevice(deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date());
+ Position position = null;
+ if (decodedMessage != null) {
+ if (decodedMessage instanceof Position) {
+ position = (Position) decodedMessage;
+ } else if (decodedMessage instanceof Collection) {
+ Collection positions = (Collection) decodedMessage;
+ if (!positions.isEmpty()) {
+ position = (Position) positions.iterator().next();
+ }
+ }
+ }
+ if (position != null) {
+ Context.getConnectionManager().updateDevice(position.getDeviceId(), Device.STATUS_ONLINE, new Date());
+ } else {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession != null) {
+ Context.getConnectionManager().updateDevice(deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date());
+ }
}
}