Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Various minor geofence updates

Rich Turner78cdfe02b57c
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
index 5833adc8c..d6f4a0923 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
@@ -410,7 +410,7 @@ public class RulesEngine<T extends Ruleset> {
public void updateFact(AssetState assetState, boolean fireImmediately) {
facts.putAssetState(assetState);
- trackLocationPredicates = assetState.getAttributeName().equals("location");
+ trackLocationPredicates = trackLocationPredicates || assetState.getAttributeName().equals("location");
if (fireImmediately) {
fire();
}
@@ -418,13 +418,13 @@ public class RulesEngine<T extends Ruleset> {
public void removeFact(AssetState assetState) {
facts.removeAssetState(assetState);
- trackLocationPredicates = assetState.getAttributeName().equals("location");
+ trackLocationPredicates = trackLocationPredicates || assetState.getAttributeName().equals("location");
fire();
}
public void insertFact(String expires, AssetState assetState) {
facts.insertAssetEvent(expires, assetState);
- trackLocationPredicates = assetState.getAttributeName().equals("location");
+ trackLocationPredicates = trackLocationPredicates || assetState.getAttributeName().equals("location");
fire();
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
index d100124a0..8ef542e63 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
@@ -80,10 +80,12 @@ public class RulesFacts extends Facts implements RuleListener {
}
protected void startTrackingLocationRules() {
+ LOG.finer("Tracking location predicate rules: started");
trackLocationRules = true;
}
protected List<RulesEngine.AssetStateLocationPredicates> stopTrackingLocationRules() {
+ LOG.finer("Tracking location predicate rules: stopping");
trackLocationRules = false;
Map<String, Set<BaseAssetQuery.LocationPredicate>> assetStateLocationPredicateMap = this.assetStateLocationPredicateMap;
this.assetStateLocationPredicateMap = null;
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
index e34186fd9..ca0e0e425 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -280,9 +280,12 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
public GeofenceDefinition[] getAssetGeofences(String assetId) {
return withLockReturning(getClass().getSimpleName() + "::getAssetGeofences", () -> {
+ LOG.finest("Requesting geofences for asset: " + assetId);
+
for (GeofenceAssetAdapter geofenceAdapter : geofenceAssetAdapters) {
GeofenceDefinition[] geofences = geofenceAdapter.getAssetGeofences(assetId);
if (geofences != null) {
+ LOG.finest("Retrieved geofences from geofence adapter '" + geofenceAdapter.getName() + "' for asset: " + assetId);
return geofences;
}
}
@@ -651,6 +654,8 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
withLock(getClass().getSimpleName() + "::updateAssetState", () -> {
// TODO: implement rules processing error state handling
+ LOG.fine("Updating asset state: " + assetState);
+
// Get the chain of rule engines that we need to pass through
List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealmId(), assetState.getPath());
@@ -818,17 +823,14 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
}
if (assetsWithModifiedLocationPredicates.size() != initialModifiedCount) {
- if (scheduledGeofenceProcessor != null) {
- scheduledGeofenceProcessor.cancel(false);
- }
- scheduledGeofenceProcessor = executorService.schedule(this::processModifiedGeofences,
- GEOFENCE_PROCESSING_DEBOUNCE_MILLIS);
+ processModifiedGeofences();
}
});
}
protected void processModifiedGeofences() {
withLock(getClass().getSimpleName() + "::processModifiedGeofences", () -> {
+ LOG.finest("Processing geofence modifications: modified asset geofence count=" + assetsWithModifiedLocationPredicates.size());
boolean isFirstRun = firstGeofenceProcessorRun;
firstGeofenceProcessorRun = false;
@@ -859,11 +861,11 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
});
for (GeofenceAssetAdapter geofenceAssetAdapter : geofenceAssetAdapters) {
- LOG.info("Passing modified geofences to adapter: " + geofenceAssetAdapter.getName());
+ LOG.finest("Passing modified geofences to adapter: " + geofenceAssetAdapter.getName());
geofenceAssetAdapter.processLocationPredicates(assetLocationPredicates, isFirstRun);
if (assetLocationPredicates.isEmpty()) {
- LOG.info("All modified geofences handled");
+ LOG.finest("All modified geofences handled");
break;
}
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
index 632ff8650..bb163bb2a 100644
--- a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
@@ -27,6 +27,7 @@ import org.openremote.container.persistence.PersistenceEvent;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.notification.NotificationService;
import org.openremote.manager.rules.RulesEngine;
+import org.openremote.manager.rules.RulesService;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetQuery;
import org.openremote.model.asset.BaseAssetQuery;
@@ -36,6 +37,7 @@ import org.openremote.model.console.ConsoleProvider;
import org.openremote.model.rules.geofence.GeofenceDefinition;
import java.util.*;
+import java.util.logging.Logger;
import java.util.stream.Collectors;
import static org.openremote.container.concurrent.GlobalLock.withLock;
@@ -52,6 +54,7 @@ import static org.openremote.model.asset.AssetType.CONSOLE;
*/
public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements GeofenceAssetAdapter, ContainerService {
+ private static final Logger LOG = Logger.getLogger(ORConsoleGeofenceAssetAdapter.class.getName());
public static final String NAME = "ORConsole";
public static final String LOCATION_POST_URL_FORMAT_TEMPLATE = "/%1$s/asset/public/%2$s/updateLocation";
protected Map<String, RulesEngine.AssetStateLocationPredicates> assetLocationPredicatesMap = new HashMap<>();
@@ -160,6 +163,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
String realm = consoleIdRealmMap.get(assetId);
if (realm == null) {
+ LOG.finest("Console ID not found in map so cannot retrieve geofences");
// Asset not supported by this adapter
return null;
}