diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-05 12:10:33 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-05 12:10:33 +1200 |
commit | 7e4ba0f57de50ddd5150f6553b51af040f2a420e (patch) | |
tree | 29f49ceae0137ca289362847b3a6a5e73fc2ba26 /src/org/traccar | |
parent | b1b22e5339d53f8b6eadb190432f4761f0380ff7 (diff) | |
download | trackermap-server-7e4ba0f57de50ddd5150f6553b51af040f2a420e.tar.gz trackermap-server-7e4ba0f57de50ddd5150f6553b51af040f2a420e.tar.bz2 trackermap-server-7e4ba0f57de50ddd5150f6553b51af040f2a420e.zip |
Use connection manager for filtering
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/FilterHandler.java | 20 | ||||
-rw-r--r-- | src/org/traccar/database/ConnectionManager.java | 5 |
2 files changed, 12 insertions, 13 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 08621dce2..69f9a55b1 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -15,17 +15,14 @@ */ package org.traccar; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Properties; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.helper.DistanceCalculator; import org.traccar.helper.Log; -import org.traccar.model.Event; import org.traccar.model.Position; public class FilterHandler extends OneToOneDecoder { @@ -36,8 +33,6 @@ public class FilterHandler extends OneToOneDecoder { private int filterDistance; private long filterLimit; - private final Map<Long, Position> lastPositions = new HashMap<Long, Position>(); - public FilterHandler( boolean filterInvalid, boolean filterZero, @@ -71,6 +66,10 @@ public class FilterHandler extends OneToOneDecoder { if (value != null) filterLimit = Long.valueOf(value) * 1000; } + private Position getLastPosition(long deviceId) { + return Context.getConnectionManager().getLastPosition(deviceId); + } + private boolean filterInvalid(Position position) { return filterInvalid && !position.getValid(); } @@ -83,7 +82,7 @@ public class FilterHandler extends OneToOneDecoder { private boolean filterDuplicate(Position position) { if (filterDuplicate) { - Position last = lastPositions.get(position.getDeviceId()); + Position last = getLastPosition(position.getDeviceId()); if (last != null) { return position.getFixTime().equals(last.getFixTime()); } else { @@ -96,7 +95,7 @@ public class FilterHandler extends OneToOneDecoder { private boolean filterDistance(Position position) { if (filterDistance != 0) { - Position last = lastPositions.get(position.getDeviceId()); + Position last = getLastPosition(position.getDeviceId()); if (last != null) { double distance = DistanceCalculator.distance( position.getLatitude(), position.getLongitude(), @@ -112,7 +111,7 @@ public class FilterHandler extends OneToOneDecoder { private boolean filterLimit(Position position) { if (filterLimit != 0) { - Position last = lastPositions.get(position.getDeviceId()); + Position last = getLastPosition(position.getDeviceId()); if (last != null) { return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit; } else { @@ -135,10 +134,7 @@ public class FilterHandler extends OneToOneDecoder { result = false; } - if (!result) { - lastPositions.put(p.getDeviceId(), p); - } else { - StringBuilder s = new StringBuilder(); + if (result) { Log.info("Position filtered from " + p.getDeviceId()); } diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index 7ef190fcf..eb22379da 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -24,7 +24,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; - import org.jboss.netty.channel.Channel; import org.traccar.Protocol; import org.traccar.helper.Log; @@ -65,6 +64,10 @@ public class ConnectionManager { } } + public Position getLastPosition(long deviceId) { + return positions.get(deviceId); + } + public synchronized Collection<Position> getInitialState(Collection<Long> devices) { List<Position> result = new LinkedList<Position>(); |