use of org.openremote.model.rules.AssetState in project openremote by openremote.
the class RulesFacts method invalidateAssetStateAndDispatch.
protected RulesFacts invalidateAssetStateAndDispatch(String assetId, String attributeName, Value value) {
// Remove the asset state from the facts, it is invalid now
getAssetStates().removeIf(assetState -> {
boolean invalid = assetState.getId().equals(assetId) && assetState.getAttributeName().equals(attributeName);
if (invalid) {
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest("Fact change (INTERNAL DELETE): " + assetState + " - on: " + loggingContext);
}
// Maintain index of all asset states for this asset by ID
Collection<AssetState> assetIdIndexCollection = assetIdIndex.get(assetState.getId());
if (assetIdIndexCollection != null) {
assetIdIndexCollection.remove(assetState);
}
// Maintain index of all asset states for this asset by type
Collection<AssetState> assetTypeIndexCollection = assetTypeIndex.get(assetState.getTypeString());
if (assetTypeIndexCollection != null) {
assetTypeIndexCollection.remove(assetState);
}
}
return invalid;
});
// Dispatch the update to the asset processing service
AttributeEvent attributeEvent = new AttributeEvent(assetId, attributeName, value);
LOG.finest("Dispatching " + attributeEvent + " - on: " + loggingContext);
assetsFacade.dispatch(attributeEvent);
return this;
}
use of org.openremote.model.rules.AssetState in project openremote by openremote.
the class RulesFacts method logFacts.
public boolean logFacts(Logger logger) {
boolean haveLog = false;
if (getAllFacts().count() > 0) {
logger.info("--------------------------------- CLOCK ---------------------------------");
LOG.info(getClock().toString());
haveLog = true;
}
List<AssetState> sortedAssetStates = new ArrayList<>(getAssetStates());
sortedAssetStates.sort(Comparator.naturalOrder());
if (sortedAssetStates.size() > 0) {
logger.info("--------------------------------- ASSET STATES (" + sortedAssetStates.size() + ") ---------------------------------");
for (AssetState assetState : sortedAssetStates) {
logger.info(assetState.toString());
}
haveLog = true;
}
List<TemporaryFact<AssetState>> sortedAssetEvents = new ArrayList<>(getAssetEvents());
if (sortedAssetEvents.size() > 0) {
logger.info("--------------------------------- ASSET EVENTS (" + sortedAssetEvents.size() + ") ---------------------------------");
sortedAssetEvents.sort(Comparator.comparing(TemporaryFact::getTime));
for (TemporaryFact<AssetState> assetEvent : sortedAssetEvents) {
logger.info(assetEvent.toString());
}
haveLog = true;
}
Map<String, Object> namedFacts = getNamedFacts();
List<String> names = new ArrayList<>(namedFacts.keySet());
names.sort(Comparator.naturalOrder());
if (names.size() > 0) {
logger.info("--------------------------------- NAMED FACTS (" + names.size() + ") ---------------------------------");
for (String name : names) {
logger.info(String.format("%s => %s", name, namedFacts.get(name)));
}
haveLog = true;
}
if (getAnonymousFacts().size() > 0) {
logger.info("--------------------------------- ANONYMOUS FACTS (" + getAnonymousFacts().size() + ") ---------------------------------");
for (Object o : getAnonymousFacts()) {
logger.info(String.format("%s", o));
}
haveLog = true;
}
return haveLog;
}
Aggregations