aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/FilterHandler.java20
-rw-r--r--src/org/traccar/database/ConnectionManager.java5
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>();