From 9034cd07e95320a37a0f788ee6eaa546af5f4df1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 1 Oct 2015 10:16:42 +1300 Subject: Implemenet future message filtering --- src/org/traccar/FilterHandler.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index c601016b4..e24de487f 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -19,18 +19,24 @@ import org.traccar.helper.DistanceCalculator; import org.traccar.helper.Log; import org.traccar.model.Position; +import java.util.Date; + public class FilterHandler extends BaseDataHandler { + private static final long FILTER_FUTURE_LIMIT = 5 * 60 * 1000; + private final boolean filterInvalid; private final boolean filterZero; private final boolean filterDuplicate; + private final boolean filterFuture; private final int filterDistance; private final long filterLimit; - + public FilterHandler( boolean filterInvalid, boolean filterZero, boolean filterDuplicate, + boolean filterFuture, int filterDistance, long filterLimit) { @@ -38,6 +44,7 @@ public class FilterHandler extends BaseDataHandler { this.filterZero = filterZero; this.filterDuplicate = filterDuplicate; this.filterDistance = filterDistance; + this.filterFuture = filterFuture; this.filterLimit = filterLimit; } @@ -47,6 +54,7 @@ public class FilterHandler extends BaseDataHandler { filterInvalid = config.getBoolean("filter.invalid"); filterZero = config.getBoolean("filter.zero"); filterDuplicate = config.getBoolean("filter.duplicate"); + filterFuture = config.getBoolean("filter.future"); filterDistance = config.getInteger("filter.distance"); filterLimit = config.getLong("filter.limit") * 1000; } @@ -80,6 +88,10 @@ public class FilterHandler extends BaseDataHandler { return false; } } + + private boolean filterFuture(Position position) { + return filterFuture && (position.getFixTime().getTime() > System.currentTimeMillis() + FILTER_FUTURE_LIMIT); + } private boolean filterDistance(Position position) { if (filterDistance != 0) { @@ -116,6 +128,7 @@ public class FilterHandler extends BaseDataHandler { filterInvalid(p) || filterZero(p) || filterDuplicate(p) || + filterFuture(p) || filterDistance(p); if (filterLimit(p)) { -- cgit v1.2.3