aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-05-04 19:56:42 -0700
committerAnton Tananaev <anton@traccar.org>2024-05-04 19:56:42 -0700
commit5d647be37332790aab41731d52e8dcadac9d5eb4 (patch)
treecbd5414673095d05519298da1807876e1ca46f24 /src/main/java/org/traccar/handler
parent5d131bdb8f9a49d5da508eb5073d21014f7185a2 (diff)
downloadtrackermap-server-5d647be37332790aab41731d52e8dcadac9d5eb4.tar.gz
trackermap-server-5d647be37332790aab41731d52e8dcadac9d5eb4.tar.bz2
trackermap-server-5d647be37332790aab41731d52e8dcadac9d5eb4.zip
Improve daily limit throttling
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 796c302fb..3bb7ef426 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -53,6 +53,7 @@ public class FilterHandler extends BasePositionHandler {
private final int filterMaxSpeed;
private final long filterMinPeriod;
private final int filterDailyLimit;
+ private final long filterDailyLimitInterval;
private final boolean filterRelative;
private final long skipLimit;
private final boolean skipAttributes;
@@ -77,6 +78,7 @@ public class FilterHandler extends BasePositionHandler {
filterMaxSpeed = config.getInteger(Keys.FILTER_MAX_SPEED);
filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000L;
filterDailyLimit = config.getInteger(Keys.FILTER_DAILY_LIMIT);
+ filterDailyLimitInterval = config.getInteger(Keys.FILTER_DAILY_LIMIT_INTERVAL) * 1000L;
filterRelative = config.getBoolean(Keys.FILTER_RELATIVE);
skipLimit = config.getLong(Keys.FILTER_SKIP_LIMIT) * 1000;
skipAttributes = config.getBoolean(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE);
@@ -164,9 +166,12 @@ public class FilterHandler extends BasePositionHandler {
return false;
}
- private boolean filterDailyLimit(Position position) {
- if (filterDailyLimit != 0) {
- return statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit;
+ private boolean filterDailyLimit(Position position, Position last) {
+ if (filterDailyLimit != 0
+ && statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit) {
+ long lastTime = last != null ? last.getFixTime().getTime() : 0;
+ long interval = position.getFixTime().getTime() - lastTime;
+ return filterDailyLimitInterval <= 0 || interval < filterDailyLimitInterval;
}
return false;
}
@@ -216,20 +221,18 @@ public class FilterHandler extends BasePositionHandler {
if (filterApproximate(position)) {
filterType.append("Approximate ");
}
- if (filterDailyLimit(position)) {
- filterType.append("DailyLimit ");
- }
// filter out excessive data
long deviceId = position.getDeviceId();
- if (filterDuplicate || filterStatic || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0) {
- Position preceding = null;
+ if (filterDuplicate || filterStatic
+ || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0 || filterDailyLimit > 0) {
+ Position preceding;
if (filterRelative) {
try {
Date newFixTime = position.getFixTime();
preceding = getPrecedingPosition(deviceId, newFixTime);
} catch (StorageException e) {
- LOGGER.warn("Error retrieving preceding position; fallbacking to last received position.", e);
+ LOGGER.warn("Error retrieving preceding position; fall backing to last received position.", e);
preceding = cacheManager.getPosition(deviceId);
}
} else {
@@ -250,6 +253,9 @@ public class FilterHandler extends BasePositionHandler {
if (filterMinPeriod(position, preceding)) {
filterType.append("MinPeriod ");
}
+ if (filterDailyLimit(position, preceding)) {
+ filterType.append("DailyLimit ");
+ }
}
Device device = cacheManager.getObject(Device.class, deviceId);