diff options
author | Jed <Jed@192.168.1.100> | 2014-09-08 19:14:20 +0800 |
---|---|---|
committer | Jed <Jed@192.168.1.100> | 2014-09-08 19:14:20 +0800 |
commit | 6a26740a4e74b2a627ad2de4b764a0c7dfdf6ca2 (patch) | |
tree | fa42ea40d2330d5ff0ba2acc2d1657655accf4b8 /src/org/traccar/TrackerEventHandler.java | |
parent | 9bad8efca5f64b60d5525b3858f42ac6cd6be272 (diff) | |
download | trackermap-server-6a26740a4e74b2a627ad2de4b764a0c7dfdf6ca2.tar.gz trackermap-server-6a26740a4e74b2a627ad2de4b764a0c7dfdf6ca2.tar.bz2 trackermap-server-6a26740a4e74b2a627ad2de4b764a0c7dfdf6ca2.zip |
Updated TrackerEventHandler to only trigger UpdateLatestPosition on the last record processed and pass the position object to the function
Added database property to Device class
Updated DatabaseDataManager to allow the use of placeholder _database_ in queries
Diffstat (limited to 'src/org/traccar/TrackerEventHandler.java')
-rw-r--r-- | src/org/traccar/TrackerEventHandler.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index 6deeaad9b..f7858fea4 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -39,7 +39,7 @@ public class TrackerEventHandler extends IdleStateAwareChannelHandler { dataManager = newDataManager; } - private void processSinglePosition(Position position) { + private Long processSinglePosition(Position position) { if (position == null) { Log.info("processSinglePosition null message"); } else { @@ -52,24 +52,34 @@ public class TrackerEventHandler extends IdleStateAwareChannelHandler { } // Write position to database + Long id = null; try { - Long id = dataManager.addPosition(position); - if (id != null) { - dataManager.updateLatestPosition(position.getDeviceId(), id); - } + id = dataManager.addPosition(position); } catch (Exception error) { Log.warning(error); } + return id; } @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { + Long id = null; + Position lastPostition = null; if (e.getMessage() instanceof Position) { - processSinglePosition((Position) e.getMessage()); + id = processSinglePosition((Position) e.getMessage()); + lastPostition = (Position) e.getMessage(); } else if (e.getMessage() instanceof List) { List<Position> positions = (List<Position>) e.getMessage(); for (Position position : positions) { - processSinglePosition(position); + id = processSinglePosition(position); + lastPostition = position; + } + } + if (id != null) { + try { + dataManager.updateLatestPosition(lastPostition, id); + } catch (Exception error) { + Log.warning(error); } } } |