100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Cleaned up attribute event processing
Christian Bauer11c442f95b53
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.javaindex 52e653131..7de04c7aa 100644--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java@@ -223,26 +223,25 @@ public abstract class AbstractProtocol implements Protocol {/*** Send an arbitrary {@link AttributeState} through the processing chain- * using the current system time as the timestamp.+ * using the current system time as the timestamp. Use {@link #updateLinkedAttribute}+ * to publish new sensor values, which performs additional verification and uses a+ * different messaging queue.*/protected void sendAttributeEvent(AttributeState state) {- sendAttributeEvent(new AttributeEvent(state, timerService.getCurrentTimeMillis()));+ assetService.sendAttributeEvent(new AttributeEvent(state, timerService.getCurrentTimeMillis()));}/*** Send an arbitrary {@link AttributeEvent} through the processing chain.+ * Use {@link #updateLinkedAttribute} to publish new sensor values, which performs+ * additional verification and uses a different messaging queue.*/- protected void sendAttributeEvent(AttributeEvent attributeEvent) {- LOG.info("Sending attribute event from protocol '" + getProtocolName() + "': " + attributeEvent);- // TODO: Decide whether protocols should be allowed to send arbitrary attribute events to read only attributes- // Use same mechanism as clients - cannot write to readonly attributes- //assetProcessingService.sendAttributeEvent();- // Use special route for protocols to allow write on readonly attributes- producerTemplate.sendBodyAndHeader(SENSOR_QUEUE, attributeEvent, "isSensorUpdate", false);+ protected void sendAttributeEvent(AttributeEvent event) {+ assetService.sendAttributeEvent(event);}/**- * Update the value of a linked attribute.+ * Update the value of a linked attribute. Call this to publish new sensor values.*/protected void updateLinkedAttribute(AttributeState state, long timestamp) {AttributeEvent attributeEvent = new AttributeEvent(state, timestamp);@@ -251,7 +250,8 @@ public abstract class AbstractProtocol implements Protocol {}/**- * Update the value of a linked attribute.+ * Update the value of a linked attribute, with the current system time as event time.+ * Call this to publish new sensor values.*/protected void updateLinkedAttribute(AttributeState state) {updateLinkedAttribute(state, timerService.getCurrentTimeMillis());diff --git a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.javaindex 1d0ff08c5..37d4b4f19 100644--- a/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java+++ b/agent/src/main/java/org/openremote/agent/protocol/ProtocolAssetService.java@@ -21,15 +21,22 @@ package org.openremote.agent.protocol;import org.openremote.container.ContainerService;import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.attribute.AttributeEvent;/*** Interface for protocols to perform limited asset related operations.- * <p>- * <ul>- * <li>Update their own protocol configurations</li>- * </ul>*/public interface ProtocolAssetService extends ContainerService {- // TODO: Find a way of limiting protocols to only modifying their own protocol configurations++ /**+ * Protocols can update their own protocol configuration, for example, to store configuration+ * details such as temporary access (e.g. OAuth offline) tokens.+ */void updateProtocolConfiguration(AssetAttribute protocolConfiguration);++ /**+ * Protocols can send arbitrary attribute change events for regular processing.+ */+ void sendAttributeEvent(AttributeEvent attributeEvent);+}diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.javaindex dd3ac0999..bc393671c 100644--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java@@ -34,7 +34,6 @@ import java.util.logging.Logger;import static org.openremote.agent.protocol.macro.MacroConfiguration.META_MACRO_ACTION;import static org.openremote.agent.protocol.macro.MacroConfiguration.isValidMacroConfiguration;-import static org.openremote.model.Constants.ASSET_META_NAMESPACE;import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;/**@@ -49,6 +48,7 @@ public class MacroProtocol extends AbstractProtocol {private static final Logger LOG = Logger.getLogger(MacroProtocol.class.getName());public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":macro";+/*** Use as value of {@link org.openremote.model.asset.AssetMeta#PROTOCOL_PROPERTY} meta item to* link an attribute to a macro action's value (allows reading/writing of macro action value).@@ -56,15 +56,16 @@ public class MacroProtocol extends AbstractProtocol {* Use in conjunction with {@link #META_MACRO_ACTION_INDEX} to determine which macro action to* link to (defaults to 0 if not present).*/- public static final String PROPERTY_MACRO_ACTION = PROTOCOL_NAMESPACE + ":macro";+ public static final String PROPERTY_MACRO_ACTION = PROTOCOL_NAME + ":action";/*** Use in combination with {@link #PROPERTY_MACRO_ACTION} on linked attributes to read/write* a macro action's value. Value should be of type {@link org.openremote.model.value.ValueType#NUMBER}.*/- public static final String META_MACRO_ACTION_INDEX = ASSET_META_NAMESPACE + ":macroActionIndex";+ public static final String META_MACRO_ACTION_INDEX = PROTOCOL_NAME + ":actionIndex";class MacroExecutionTask {+AttributeRef attributeRef;List<MacroAction> actions;boolean repeat;@@ -86,7 +87,11 @@ public class MacroProtocol extends AbstractProtocol {// Update the command Status of this attribute - We use a timestamp slightly in the past otherwise// it is possible for COMPLETED status update below to have the same timestamp and to then be rejected// by the asset processing service- updateLinkedAttribute(new AttributeState(attributeRef, AttributeExecuteStatus.RUNNING.asValue()), System.currentTimeMillis()-10);+ updateLinkedAttribute(new AttributeState(+ attributeRef,+ AttributeExecuteStatus.RUNNING.asValue()),+ timerService.getCurrentTimeMillis()-10+ );run();}diff --git a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.propertiesindex 4c04508ac..455cc8a0a 100644--- a/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties+++ b/manager/client/src/main/resources/org/openremote/manager/client/i18n/ManagerMessages.properties@@ -191,7 +191,7 @@ attributeType[DISTANCE_CM]=Distance in centimetresattributeType[DISTANCE_MM]=Distance in millimetresattributeType[DISTANCE_IN]=Distance in inchattributeType[DISTANCE_FT]=Distance in feet-attributeType[DISTANCE_YARD]=Dinstance in yard+attributeType[DISTANCE_YARD]=Distance in yardattributeType[CO2_PPM]=CO2 Level in PPMattributeType[HUMIDITY_PERCENTAGE]=Humidity percentageattributeType[HUMIDITY_GPCM]=Humidity in grams per cubic metresdiff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.javaindex a2688a9f6..90e68f0cd 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java@@ -27,6 +27,7 @@ import org.openremote.container.ContainerService;import org.openremote.container.message.MessageBrokerService;import org.openremote.container.message.MessageBrokerSetupService;import org.openremote.container.persistence.PersistenceEvent;+import org.openremote.manager.server.asset.AssetProcessingService;import org.openremote.manager.server.asset.AssetStorageService;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.datapoint.AssetDatapointService;@@ -66,6 +67,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Consprivate static final Logger LOG = Logger.getLogger(AgentService.class.getName());protected Container container;+ protected AssetProcessingService assetProcessingService;protected AssetStorageService assetStorageService;protected AssetDatapointService assetDatapointService;protected MessageBrokerService messageBrokerService;@@ -75,6 +77,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons@Overridepublic void init(Container container) throws Exception {this.container = container;+ assetProcessingService = container.getService(AssetProcessingService.class);assetStorageService = container.getService(AssetStorageService.class);assetDatapointService = container.getService(AssetDatapointService.class);messageBrokerService = container.getService(MessageBrokerService.class);@@ -143,11 +146,8 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons/*** This should only be called by protocol implementations to request an update to- * one of their own protocol configuration attributes. The {@link ProtocolAssetService}- * interface was implemented here because the sendAttributeEvent already exists here- * and there are already protocol related things here anyway.+ * one of their own protocol configuration attributes.*/- // TODO: Need a way of restricting protocols to their own protocolConfigurations@Overridepublic void updateProtocolConfiguration(AssetAttribute protocolConfiguration) {if (protocolConfiguration == null || !protocolConfiguration.getReference().isPresent()) {@@ -175,6 +175,11 @@ public class AgentService extends RouteBuilder implements ContainerService, ConsassetStorageService.merge(agent);}+ @Override+ public void sendAttributeEvent(AttributeEvent attributeEvent) {+ assetProcessingService.sendAttributeEvent(attributeEvent, false);+ }+/*** Looks for new, modified and obsolete protocol configurations and links / unlinks any associated* attributes@@ -513,18 +518,19 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons}/**- * If this update is not for an asset of type THING or it has been initiated by- * a protocol then we ignore it.+ * If this is not a southbound update from a client, or if the changed attribute is not linked to+ * an agent's protocol configuration, we ignore it.* <p>- * Otherwise we push the update to the protocol to handle and prevent any further- * processing of this event by the processing chain, the protocol should raise- * sensor updates as required (i.e. the protocol is responsible for synchronising state)+ * Otherwise we push the update to the attributes' linked protocol to handle and prevent any further+ * processing of this event by the processing chain. The protocol should raise sensor updates as+ * required (i.e. the protocol is responsible for synchronising state with the database).*/@Overridepublic void accept(AssetState assetState) {- // If update was initiated by a protocol ignore it- if (assetState.isNorthbound()) {- LOG.fine("Ignoring as it came from a protocol: " + assetState);+ if (assetState.isSouthbound()) {+ LOG.fine("Handling south-bound update: " + assetState);+ } else {+ LOG.fine("Ignoring non-client update: " + assetState);return;}diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.javaindex 391f429a9..f7682fa31 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetProcessingService.java@@ -33,6 +33,7 @@ import org.openremote.manager.server.event.EventService;import org.openremote.manager.server.rules.RulesService;import org.openremote.manager.server.security.ManagerIdentityService;import org.openremote.manager.shared.security.ClientRole;+import org.openremote.model.ValidationFailure;import org.openremote.model.asset.*;import org.openremote.model.attribute.AttributeEvent;import org.openremote.model.attribute.AttributeExecuteStatus;@@ -115,7 +116,7 @@ import static org.openremote.model.asset.agent.AgentLink.getAgentLink;* <p>* Checks if attribute has {@link org.openremote.model.asset.AssetMeta#STORE_DATA_POINTS} meta item with a value of true* and if it does then the {@link AttributeEvent} is stored in a time series DB. Then allows the message to continue- * if the commit was successful. TODO Should the datapoint service only store northbound updates?+ * if the commit was successful.*/public class AssetProcessingService extends RouteBuilder implements ContainerService {@@ -204,7 +205,8 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer@Overridepublic void configure() throws Exception {- // Process attribute events from protocols+ // Process new sensor values from protocols, must be events for+ // attributes linked to an agent's protocol configurationsfrom(SENSOR_QUEUE).filter(body().isInstanceOf(AttributeEvent.class)).process(exchange -> {@@ -213,22 +215,58 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerProtocol.SENSOR_QUEUE_SOURCE_PROTOCOL, "Unknown Protocol", String.class);LOG.fine("Received from protocol '" + protocolName + "' on sensor queue: " + event);- // Can either come from onUpdateSensor or sendAttributeUpdate- boolean isSensorUpdate = (boolean) exchange.getIn().getHeader("isSensorUpdate", true);- if (isSensorUpdate) {- processSensorUpdate(protocolName, event);- } else {- updateAttributeValue(event, true);++ ServerAsset asset = assetStorageService.find(event.getEntityId(), true);++ if (asset == null) {+ LOG.warning(+ "Sensor update received from protocol '" + protocolName + "' for an asset that cannot be found: "+ + event.getEntityId()+ );+ return;+ }++ LOG.fine("Processing sensor " + event + " for asset: " + asset);++ // Get the attribute and check it is actually linked to an agent (although the+ // event comes from a Protocol, we can not assume that the attribute is still linked,+ // consider a protocol that receives a batch of messages because a gateway was offline+ // for a day)+ AssetAttribute attribute = asset.getAttribute(event.getAttributeName()).orElse(null);++ if (attribute == null) {+ LOG.warning(+ "Processing sensor update from protocol '" + protocolName+ + "' failed, no attribute or not linked to an agent: " + event+ );+ return;}++ Optional<AssetAttribute> protocolConfiguration =+ getAgentLink(attribute)+ .flatMap(agentService::getProtocolConfiguration);++ if (!protocolConfiguration.isPresent()) {+ LOG.warning(+ "Processing sensor update from protocol '" + protocolName+ + "' failed, linked agent protocol configuration not found: " + event+ );+ return;+ }++ // Process as non-client source (not southbound)+ processUpdate(asset, attribute, event, false);+});- // Process attribute events from clients+ // Process arbitrary attribute eventsfrom(ASSET_QUEUE).filter(body().isInstanceOf(AttributeEvent.class)).process(exchange -> {AttributeEvent event = exchange.getIn().getBody(AttributeEvent.class);- LOG.fine("Received on asset queue: " + event);- updateAttributeValue(event, false);+ boolean southbound = exchange.getIn().getHeader(AttributeEvent.HEADER_SOUTHBOUND, true, Boolean.class);+ LOG.fine("Received (southbound: " + southbound + ") on asset queue: " + event);+ updateAttributeValue(event, southbound);});// React if a client wants to write attribute state@@ -245,7 +283,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer// Superuser can write allif (auth.isSuperUser()) {- sendAttributeEvent(event);+ sendAttributeEvent(event, true);return;}@@ -276,32 +314,34 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerreturn;// Put it on the asset queue- sendAttributeEvent(event);+ sendAttributeEvent(event, true);});}+ /**+ * Send attribute change events, with a client origin, into the {@link #ASSET_QUEUE}.+ *+ */public void sendAttributeEvent(AttributeEvent attributeEvent) {- messageBrokerService.getProducerTemplate().sendBody(ASSET_QUEUE, attributeEvent);+ sendAttributeEvent(attributeEvent, true);}/**- * This is the entry point for any attribute value change event in the entire system.- * <p>- * Ingestion is asynchronous, through either- * {@link org.openremote.agent.protocol.Protocol#SENSOR_QUEUE} or {@link #ASSET_QUEUE}.- * <p>- * This deals with single attribute value changes and pushes them through the attribute event- * processing chain where each consumer is given the opportunity to consume the event or allow- * it progress to the next consumer {@link AssetState.ProcessingStatus}.- * <p>- * NOTE: An attribute value can be changed during Asset CRUD but this does not come through- * this route but is handled separately see {@link AssetResourceImpl}. Any attribute values- * assigned during Asset CRUD can be thought of as the attributes initial value and is subject- * to change by the following actors (depending on attribute meta etc.) All actors use this- * entry point to initiate an attribute value change: Sensor updates from protocols, attribute- * write requests from clients, and attribute write dispatching as rules RHS action.+ * Send attribute change events into the {@link #ASSET_QUEUE}.+ *+ * @param southBound <code>true</code> if the event origin is a client, and not from a+ * protocol or internal (rules) processing.*/- private void updateAttributeValue(AttributeEvent attributeEvent, boolean fromProtocol) {+ public void sendAttributeEvent(AttributeEvent attributeEvent, boolean southBound) {+ messageBrokerService.getProducerTemplate().sendBodyAndHeader(+ ASSET_QUEUE,+ attributeEvent,+ AttributeEvent.HEADER_SOUTHBOUND,+ southBound+ );+ }++ private void updateAttributeValue(AttributeEvent attributeEvent, boolean southBound) {// Check this event relates to a valid assetServerAsset asset = assetStorageService.find(attributeEvent.getEntityId(), true);@@ -327,15 +367,13 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer}// Prevent editing of read only attributes- // TODO This also means a rule RHS can't write a read-only attribute with Assets#dispatch!- // TODO should protocols be allowed to write to read-only attributes- if (!fromProtocol && attribute.get().isReadOnly()) {- LOG.warning("Ignoring " + attributeEvent + ", attribute is read-only in: " + asset);+ if (southBound && attribute.get().isReadOnly()) {+ LOG.warning("Ignoring southbound " + attributeEvent + ", attribute is read-only in: " + asset);return;}- // If attribute is marked as executable and not from northbound only allow write AttributeExecuteStatus to be sent- if (!fromProtocol && attribute.get().isExecutable()) {+ // If attribute is marked as executable and southbound only allow write AttributeExecuteStatus to be sent+ if (southBound && attribute.get().isExecutable()) {Optional<AttributeExecuteStatus> status = attributeEvent.getValue().flatMap(Values::getString).flatMap(AttributeExecuteStatus::fromString);@@ -351,59 +389,13 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer}}- processUpdate(asset, attribute.get(), attributeEvent, false);- }-- /**- * We get here if a protocol pushes a sensor update message.- */- protected void processSensorUpdate(String protocolName, AttributeEvent attributeEvent) {- ServerAsset asset = assetStorageService.find(attributeEvent.getEntityId(), true);-- if (asset == null) {- LOG.warning(- "Sensor update received from protocol '" + protocolName + "' for an asset that cannot be found: "- + attributeEvent.getEntityId()- );- return;- }-- LOG.fine("Processing sensor " + attributeEvent + " for asset: " + asset);-- // Get the attribute and check it is actually linked to an agent (although the- // event comes from a Protocol, we can not assume that the attribute is still linked,- // consider a protocol that receives a batch of messages because a gateway was offline- // for a day)- AssetAttribute attribute = asset.getAttribute(attributeEvent.getAttributeName()).orElse(null);-- if (attribute == null) {- LOG.warning(- "Processing sensor update from protocol '" + protocolName- + "' failed, no attribute or not linked to an agent: " + attributeEvent- );- return;- }-- Optional<AssetAttribute> protocolConfiguration =- getAgentLink(attribute)- .flatMap(agentService::getProtocolConfiguration);-- if (!protocolConfiguration.isPresent()) {- LOG.warning(- "Processing sensor update from protocol '" + protocolName- + "' failed, linked agent protocol configuration not found: " + attributeEvent- );- return;- }-- // Protocols can write to readonly attributes (i.e. sensor attributes) so no need to check readonly flag- processUpdate(asset, attribute, attributeEvent, true);+ processUpdate(asset, attribute.get(), attributeEvent, southBound);}protected void processUpdate(ServerAsset asset,AssetAttribute attribute,AttributeEvent attributeEvent,- boolean northbound) {+ boolean southbound) {// Ensure timestamp of event is not in the future as that would essentially block access to// the attribute until after that time (maybe that is desirable behaviour)// Allow a leniency of 1s@@ -429,11 +421,13 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerreturn;}- // Set new value and event timestamp on attribute, thus validating any attribute constraints- try {- attribute.setValue(attributeEvent.getValue().orElse(null), attributeEvent.getTimestamp());- } catch (IllegalArgumentException ex) {- LOG.log(Level.WARNING, "Ignoring " + attributeEvent + ", attribute constraint violation in: " + asset, ex);+ // Set new value and event timestamp on attribute+ attribute.setValue(attributeEvent.getValue().orElse(null), attributeEvent.getTimestamp());++ // Validate constraints of attribute+ List<ValidationFailure> validationFailures = attribute.getValidationFailures();+ if (!validationFailures.isEmpty()) {+ LOG.warning("Validation failure(s) " + validationFailures + ", can't process update of: " + attribute);return;}@@ -443,10 +437,23 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerattribute,lastStateEvent.flatMap(AttributeEvent::getValue).orElse(null),lastStateEvent.map(AttributeEvent::getTimestamp).orElse(-1L),- northbound)+ southbound));}+ /*+ * This deals with single attribute value changes and pushes them through the attribute event+ * processing chain where each consumer is given the opportunity to consume the event or allow+ * it progress to the next consumer {@link AssetState.ProcessingStatus}.+ * <p>+ * NOTE: An attribute value can be changed during Asset CRUD but this does not come through+ * this route but is handled separately see {@link AssetResourceImpl}. Any attribute values+ * assigned during Asset CRUD can be thought of as the attributes initial value and is subject+ * to change by the following actors (depending on attribute meta etc.) All actors use this+ * entry point to initiate an attribute value change: Sensor updates from protocols, attribute+ * write requests from protocols, attribute write requests from clients, and attribute write+ * dispatching as rules RHS action.+ */protected void processUpdate(AssetState assetState) {try {long currentMillis = timerService.getCurrentTimeMillis();diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.javaindex e82271578..c69aa80ed 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java@@ -243,7 +243,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicint invalid = 0;for (AssetAttribute attribute : asset.getAttributesList()) {List<ValidationFailure> validationFailures = attribute.getValidationFailures();- if (validationFailures.size() > 0) {+ if (!validationFailures.isEmpty()) {LOG.warning("Validation failure(s) " + validationFailures + ", can't store: " + attribute);invalid++;}diff --git a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesEngine.java b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesEngine.javaindex 9666da24c..83023ce68 100644--- a/manager/server/src/main/java/org/openremote/manager/server/rules/RulesEngine.java+++ b/manager/server/src/main/java/org/openremote/manager/server/rules/RulesEngine.java@@ -635,7 +635,7 @@ public class RulesEngine<T extends Ruleset> {}LOG.fine("Dispatching on " + RulesEngine.this + ": " + event);- assetProcessingService.sendAttributeEvent(event);+ assetProcessingService.sendAttributeEvent(event, false);}}};diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovyindex d83d0c629..4fdcaf361 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetDatapointTest.groovy@@ -20,7 +20,10 @@ class AssetDatapointTest extends Specification implements ManagerContainerTraitwhen: "the demo agent and thing have been deployed"def serverPort = findEphemeralPort()- def container = startContainerNoDemoRules(defaultConfig(serverPort), defaultServices())+ def container = startContainerNoDemoRules(+ defaultConfig(serverPort),+ defaultServices()+ )def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)def simulatorProtocol = container.getService(SimulatorProtocol.class)def assetStorageService = container.getService(AssetStorageService.class)diff --git a/model/src/main/java/org/openremote/model/AbstractValueHolder.java b/model/src/main/java/org/openremote/model/AbstractValueHolder.javaindex 935211dbe..7ccdc9a62 100644--- a/model/src/main/java/org/openremote/model/AbstractValueHolder.java+++ b/model/src/main/java/org/openremote/model/AbstractValueHolder.java@@ -88,19 +88,19 @@ public abstract class AbstractValueHolder {}}- public void setValue(Value... values) throws IllegalArgumentException {+ public void setValue(Value... values) {setValue(Values.createArray().addAll(values));}- public void setValue(String string) throws IllegalArgumentException {+ public void setValue(String string) {setValue(Values.create(string));}- public void setValue(Double number) throws IllegalArgumentException {+ public void setValue(Double number) {setValue(Values.create(number));}- public void setValue(Boolean b) throws IllegalArgumentException {+ public void setValue(Boolean b) {setValue(Values.create(b));}diff --git a/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.java b/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.javaindex 3b53cbb5d..4c1125c98 100644--- a/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.java+++ b/model/src/main/java/org/openremote/model/AbstractValueTimestampHolder.java@@ -76,7 +76,7 @@ public abstract class AbstractValueTimestampHolder extends AbstractValueHolder {* Sets the value and the timestamp to system time.*/@Override- public void setValue(Value value) throws IllegalArgumentException {+ public void setValue(Value value) {super.setValue(value);setValueTimestamp();}@@ -84,7 +84,7 @@ public abstract class AbstractValueTimestampHolder extends AbstractValueHolder {/*** Sets the value and the timestamp to given time.*/- public void setValue(Value value, long timestamp) throws IllegalArgumentException {+ public void setValue(Value value, long timestamp) {setValue(value);setValueTimestamp(timestamp);}diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.javaindex d713bfacc..37c0ed58e 100644--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java@@ -71,14 +71,13 @@ public abstract class AbstractAssetUpdate {final protected long oldValueTimestamp;- // True if the update was initiated by a protocol and is being processed northbound- protected boolean northbound;+ protected boolean southbound;public AbstractAssetUpdate(Asset asset, AssetAttribute attribute) {this(asset, attribute, null, 0, false);}- public AbstractAssetUpdate(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean northbound) {+ public AbstractAssetUpdate(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean southbound) {this(attribute,asset.getCreatedOn(),@@ -96,7 +95,7 @@ public abstract class AbstractAssetUpdate {asset.getCoordinates(),oldValue,oldValueTimestamp,- northbound+ southbound);}@@ -118,7 +117,7 @@ public abstract class AbstractAssetUpdate {that.coordinates,that.oldValue,that.oldValueTimestamp,- that.northbound+ that.southbound);}@@ -129,7 +128,7 @@ public abstract class AbstractAssetUpdate {double[] coordinates,Value oldValue,long oldValueTimestamp,- boolean northbound) {+ boolean southbound) {this.attribute = attribute;this.createdOn = createdOn;this.id = id;@@ -149,7 +148,7 @@ public abstract class AbstractAssetUpdate {this.coordinates = coordinates;this.oldValue = oldValue;this.oldValueTimestamp = oldValueTimestamp;- this.northbound = northbound;+ this.southbound = southbound;}public Date getCreatedOn() {@@ -212,8 +211,12 @@ public abstract class AbstractAssetUpdate {return oldValueTimestamp;}- public boolean isNorthbound() {- return northbound;+ /**+ * True if the update was initiated by a client (and not protocol or internal) and+ * is being processed southbound.+ */+ public boolean isSouthbound() {+ return southbound;}public Value getValue() {diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.javaindex 231dc1263..97ea24940 100644--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java@@ -82,7 +82,8 @@ public enum AssetMeta implements HasUniqueResourceName {ABOUT(ASSET_META_NAMESPACE + ":about", new Access(true, false, true), ValueType.STRING),/**- * Marks the attribute as read-only.+ * Marks the attribute as read-only for clients. South-bound changes of the attribute are not possible.+ * North-bound attribute updates made by protocols and changes made by rules are possible.*/READ_ONLY(ASSET_META_NAMESPACE + ":readOnly", new Access(true, false, true), ValueType.BOOLEAN),@@ -160,7 +161,6 @@ public enum AssetMeta implements HasUniqueResourceName {* Marks an agent linked attribute as being linked to a property of the linked protocol. For example, an* attribute linked to the {@link #ENABLED} status of a protocol configuration should use this meta with* a value of "ENABLED"; other supported values are protocol dependent.- * TODO I don't understand what this does from the description*/PROTOCOL_PROPERTY(ASSET_META_NAMESPACE + ":protocolProperty", new Access(true, false, true), ValueType.STRING);diff --git a/model/src/main/java/org/openremote/model/asset/AssetState.java b/model/src/main/java/org/openremote/model/asset/AssetState.javaindex c99c462fb..74628e947 100644--- a/model/src/main/java/org/openremote/model/asset/AssetState.java+++ b/model/src/main/java/org/openremote/model/asset/AssetState.java@@ -65,8 +65,8 @@ public class AssetState extends AbstractAssetUpdate {super(asset, attribute);}- public AssetState(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean northbound) {- super(asset, attribute, oldValue, oldValueTimestamp, northbound);+ public AssetState(Asset asset, AssetAttribute attribute, Value oldValue, long oldValueTimestamp, boolean southbound) {+ super(asset, attribute, oldValue, oldValueTimestamp, southbound);}public ProcessingStatus getProcessingStatus() {diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java b/model/src/main/java/org/openremote/model/attribute/AttributeEvent.javaindex 79cdfed93..cc59875b1 100644--- a/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java+++ b/model/src/main/java/org/openremote/model/attribute/AttributeEvent.java@@ -31,28 +31,7 @@ import java.util.Optional;*/public class AttributeEvent extends SharedEvent {- /**- * Processing of the attribute event depends on where the event originated from.- *- * TODO Use this as header in Camel messages for conditional routing- */- public enum Source {-- /**- * The event was created by a client, it's a write request/actuator message.- */- SOUTHBOUND,-- /**- * The event was created by internal processing, for example, as a rule consequence.- */- PROCESSING,-- /**- * The event was created by a protocol, it's a value change on a sensor.- */- NORTHBOUND- }+ public static final String HEADER_SOUTHBOUND = AttributeEvent.class.getName() + ".SOUTHBOUND";public static class EntityIdFilter extends EventFilter<AttributeEvent> {