From 4004a7ed90ff7828af3e1d3fa59d3b01541c2f6f Mon Sep 17 00:00:00 2001 From: Alex Almanza <115671044+earocorn@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:12:20 -0500 Subject: [PATCH] Change auto purge config to list of auto purge configs --- .../database/system/SystemDriverDatabase.java | 29 ++++++++++--------- .../system/SystemDriverDatabaseConfig.java | 4 ++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabase.java b/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabase.java index 2a193bb74..4e24155e8 100644 --- a/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabase.java +++ b/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabase.java @@ -82,20 +82,23 @@ protected void doStart() throws SensorHubException } // start auto-purge timer thread if policy is specified and enabled - if (config.autoPurgeConfig != null && config.autoPurgeConfig.enabled) + for(var autoPurgeConfig : config.autoPurgeConfig) { - var uids = Collections.unmodifiableCollection(config.autoPurgeConfig.systemUIDs); - final IObsSystemDbAutoPurgePolicy policy = config.autoPurgeConfig.getPolicy(); - autoPurgeTimer = new Timer(); - TimerTask task = new TimerTask() { - public void run() - { - if (!db.isReadOnly()) - policy.trimStorage(db, logger, uids); - } - }; - - autoPurgeTimer.schedule(task, 0, (long)(config.autoPurgeConfig.purgePeriod*1000)); + if (autoPurgeConfig != null && autoPurgeConfig.enabled) + { + var uids = Collections.unmodifiableCollection(autoPurgeConfig.systemUIDs); + final IObsSystemDbAutoPurgePolicy policy = autoPurgeConfig.getPolicy(); + autoPurgeTimer = new Timer(); + TimerTask task = new TimerTask() { + public void run() + { + if (!db.isReadOnly()) + policy.trimStorage(db, logger, uids); + } + }; + + autoPurgeTimer.schedule(task, 0, (long)(autoPurgeConfig.purgePeriod*1000)); + } } } diff --git a/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabaseConfig.java b/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabaseConfig.java index 9efe0d9fb..7669b92bc 100644 --- a/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabaseConfig.java +++ b/sensorhub-core/src/main/java/org/sensorhub/impl/database/system/SystemDriverDatabaseConfig.java @@ -14,6 +14,8 @@ package org.sensorhub.impl.database.system; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.TreeSet; import org.sensorhub.api.config.DisplayInfo; @@ -46,7 +48,7 @@ public class SystemDriverDatabaseConfig extends DatabaseConfig @DisplayInfo(label="Automatic Purge Policy", desc="Policy for automatically purging historical data") - public HistoricalObsAutoPurgeConfig autoPurgeConfig; + public List autoPurgeConfig = new ArrayList<>(); @DisplayInfo(desc="Minimum period between database commits (in ms)")