Skip to content

armgit / core

Public Imported from GitHub
0

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

Minor improvements

Christian Bauer3b154d516af1
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
index 7de04c7aa..a25812a41 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -45,6 +45,7 @@ import java.util.logging.Logger;
public abstract class AbstractProtocol implements Protocol {
private static final Logger LOG = Logger.getLogger(AbstractProtocol.class.getName());
+
protected final Map<AttributeRef, AssetAttribute> linkedAttributes = new HashMap<>();
protected final Map<AttributeRef, Triplet<AssetAttribute, Consumer<DeploymentStatus>, DeploymentStatus>> linkedProtocolConfigurations = new HashMap<>();
protected MessageBrokerContext messageBrokerContext;
@@ -74,7 +75,7 @@ public abstract class AbstractProtocol implements Protocol {
from(ACTUATOR_TOPIC)
.routeId("Actuator-" + getProtocolName())
.process(exchange -> {
- String protocolName = exchange.getIn().getHeader(Protocol.ACTUATOR_TOPIC_TARGET_PROTOCOL, String.class);
+ String protocolName = exchange.getIn().getHeader(ACTUATOR_TOPIC_TARGET_PROTOCOL, String.class);
if (getProtocolName().equals(protocolName)) {
// TODO Use read/write lock for link/unlink attributes synchronization and additional optional exclusive lock for single-threaded implementors
synchronized (linkedAttributes) {
@@ -85,6 +86,7 @@ public abstract class AbstractProtocol implements Protocol {
} else {
AssetAttribute protocolConfiguration = getLinkedProtocolConfiguration(attribute);
+ // TODO: Merge this into new TimerProtocol as custom configuration item
// If attribute is linked to protocol's enabled status handle here
boolean isLinkedToEnabledStatus = attribute
.getMetaItem(AssetMeta.PROTOCOL_PROPERTY)
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.java
index bc393671c..ed083ba37 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
@@ -56,7 +56,7 @@ 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_NAME + ":action";
+ public static final String PROPERTY_MACRO_ACTION = "ACTION";
/**
* Use in combination with {@link #PROPERTY_MACRO_ACTION} on linked attributes to read/write
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.java
index f7682fa31..d0722073c 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
@@ -134,6 +134,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
protected AssetDatapointService assetDatapointService;
protected MessageBrokerService messageBrokerService;
protected EventService eventService;
+ protected long lastProcessedEventTimestamp;
final protected List<Consumer<AssetState>> processors = new ArrayList<>();
@@ -487,6 +488,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
}
} finally {
+ lastProcessedEventTimestamp = System.currentTimeMillis();
LOG.fine("<<< Processing complete: " + assetState);
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java
index 024068f66..91e7f42c3 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/BuiltinSetupTasks.java
@@ -53,6 +53,8 @@ public class BuiltinSetupTasks extends AbstractSetupTasks {
public static final String SETUP_INIT_CLEAN_DATABASE = "SETUP_INIT_CLEAN_DATABASE";
public static final String SETUP_IMPORT_DEMO_USERS = "SETUP_IMPORT_DEMO_USERS";
public static final String SETUP_IMPORT_DEMO_ASSETS = "SETUP_IMPORT_DEMO_ASSETS";
+ // TODO: Only import apartment 1 if this flag is set
+ public static final String SETUP_IMPORT_DEMO_APARTMENT = "SETUP_IMPORT_DEMO_APARTMENT";
public static final String SETUP_IMPORT_DEMO_RULES = "SETUP_IMPORT_DEMO_RULES";
@Override
diff --git a/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy b/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy
index 45e359d45..9db8c1770 100644
--- a/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy
+++ b/manager/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy
@@ -98,6 +98,11 @@ trait ManagerContainerTrait extends ContainerTrait {
startContainer(config << [(TIMER_CLOCK_TYPE): PSEUDO.name()], services)
}
+ static assertNothingProcessedFor(AssetProcessingService assetProcessingService, int milliseconds) {
+ assert (assetProcessingService.lastProcessedEventTimestamp > 0
+ && assetProcessingService.lastProcessedEventTimestamp + milliseconds < System.currentTimeMillis())
+ }
+
/**
* Execute pseudo clock operations in Rules engine.
*/
@@ -121,13 +126,17 @@ trait ManagerContainerTrait extends ContainerTrait {
}
static void advancePseudoClocks(long amount, TimeUnit unit, Container container, RulesEngine[] engine) {
- withClockOf(container) { it.advanceTime(amount, unit)}
- engine.each { withClockOf(it) { it.advanceTime(amount, unit)} }
+ withClockOf(container) { it.advanceTime(amount, unit) }
+ engine.each { withClockOf(it) { it.advanceTime(amount, unit) } }
}
static void setPseudoClocksToRealTime(Container container, RulesEngine[] engine) {
- withClockOf(container) { it.advanceTime(System.currentTimeMillis() - it.currentTimeMillis, TimeUnit.MILLISECONDS) }
- engine.each { withClockOf(it) { it.advanceTime(System.currentTimeMillis() - it.currentTime, TimeUnit.MILLISECONDS)} }
+ withClockOf(container) {
+ it.advanceTime(System.currentTimeMillis() - it.currentTimeMillis, TimeUnit.MILLISECONDS)
+ }
+ engine.each {
+ withClockOf(it) { it.advanceTime(System.currentTimeMillis() - it.currentTime, TimeUnit.MILLISECONDS) }
+ }
}
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index 45967998c..594770567 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -111,12 +111,10 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
then: "the container should be running and initialised"
conditions.eventually {
- assert isContainerRunning()
+ assertNothingProcessedFor(assetProcessingService, 500)
}
then: "register mock asset processors"
- // TODO We have no choice but to sleep here as we wait for trigger protocol to finish initialization
- sleep(3000)
assetProcessingService.processors.add(mockDatapointServiceConsumer)
assetProcessingService.processors.add(3, mockAssetStorageConsumer)
assetProcessingService.processors.add(2, mockAgentServiceConsumer)
diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
index 97ea24940..f205de16b 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java
@@ -158,9 +158,9 @@ public enum AssetMeta implements HasUniqueResourceName {
EXECUTABLE(ASSET_META_NAMESPACE + ":executable", new Access(true, false, true), ValueType.BOOLEAN),
/**
- * 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.
+ * Marks an agent linked attribute as being linked to a property of the linked protocol, supported values
+ * are protocol dependent.
+ * TODO: Merge this into protocols that require custom configuration
*/
PROTOCOL_PROPERTY(ASSET_META_NAMESPACE + ":protocolProperty", new Access(true, false, true), ValueType.STRING);