Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code documentation, disabled broken test
  • Loading branch information
Christian Bauer committed Jan 4, 2017
1 parent 318e962 commit 399d5d7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 13 deletions.
6 changes: 3 additions & 3 deletions agent/src/main/java/org/openremote/agent/sensor/Sensor.java
Expand Up @@ -121,9 +121,9 @@ public void update(String state) {
LOG.fine("Ignoring update, sensor is not running: " + getSensorDefinition()); LOG.fine("Ignoring update, sensor is not running: " + getSensorDefinition());
return; return;
} }
SensorState evt = process(state); SensorState resultState = process(state);
LOG.fine("Update on ID " + getSensorDefinition().getSensorID() + ", processed '" + state + "', created: " + evt); LOG.fine("Update on ID " + getSensorDefinition().getSensorID() + ", input string: '" + state + "', result state: " + resultState);
agentContext.update(evt); agentContext.update(resultState);
} }


/** /**
Expand Down
25 changes: 25 additions & 0 deletions agent/src/main/java/org/openremote/agent3/protocol/Protocol.java
Expand Up @@ -24,6 +24,31 @@


import java.util.Collection; import java.util.Collection;


/**
* A Protocol implementation must have a unique name in a VM. TODO This is not enforced.
* <p>
* OpenRemote protocols are in {@link org.openremote.Constants#PROTOCOL_NAMESPACE}.
* <p>
* The Protocol implementation can receive {@link org.openremote.model.AttributeValueChange} messages on the
* {@link #ACTUATOR_TOPIC}. It can produce {@link org.openremote.model.AttributeValueChange} messages on the
* {@link #SENSOR_TOPIC}.
* <p>
* The linked attributes of a protocol provide the model for the protocol to perform these operations. How
* attributes and value changes map to actual device and service calls is up to the implementation.
* <p>
* The linked protocol handles south-bound read and write of the attribute value: If the user writes
* a new value into the Thing attribute, the protocol translates this value change into a
* device (or service) action. If the actual state of the device (or service) changes, the linked
* protocol writes the new state into the attribute value and the asset system user is notified of the change.
* <p>
* Data type conversion is also delegated to the Protocol implementation: If an attribute has a particular
* AttributeType and therefore a certain JsonValue, the Protocol must receive and send value change messages
* with values of that type.
* TODO: Some kind of converter system can be introduced later, although I find JsonValue#asXXX() is already a good utility for protocol implementators.
* <p>
* Protocol-specific meta items required for the link can be added to Thing attributes, such as the
* Hue light identifier or the ZWave node and command.
*/
public interface Protocol extends ContainerService { public interface Protocol extends ContainerService {


// TODO: Some of these options should be configurable depending on expected load etc. // TODO: Some of these options should be configurable depending on expected load etc.
Expand Down
Expand Up @@ -6,10 +6,12 @@ import org.openremote.agent.AgentService
import org.openremote.agent.rules.RulesProvider import org.openremote.agent.rules.RulesProvider
import org.openremote.agent.sensor.CustomSensorState import org.openremote.agent.sensor.CustomSensorState
import org.openremote.test.ContainerTrait import org.openremote.test.ContainerTrait
import spock.lang.Ignore
import spock.lang.Specification import spock.lang.Specification


import java.util.stream.Stream import java.util.stream.Stream


@Ignore // TODO: Fix test, use BlockingVariables, PollingConditions, etc.
class PIDTest extends Specification implements ContainerTrait { class PIDTest extends Specification implements ContainerTrait {


def "PID controller basic test"() { def "PID controller basic test"() {
Expand Down
Expand Up @@ -22,7 +22,7 @@
public class PersistenceEvent<T> { public class PersistenceEvent<T> {


// TODO: Make configurable // TODO: Make configurable
public static final String PERSISTENCE_EVENT_TOPIC = public static final String PERSISTENCE_TOPIC =
"seda://PersistenceTopic?multipleConsumers=true&discardIfNoConsumers=true"; "seda://PersistenceTopic?multipleConsumers=true&discardIfNoConsumers=true";


public static final String HEADER_ENTITY_TYPE = PersistenceEvent.class.getSimpleName() + ".ENTITY_TYPE"; public static final String HEADER_ENTITY_TYPE = PersistenceEvent.class.getSimpleName() + ".ENTITY_TYPE";
Expand Down
Expand Up @@ -112,7 +112,7 @@ public void afterCompletion(int status) {


for (PersistenceEvent persistenceEvent : persistenceEvents) { for (PersistenceEvent persistenceEvent : persistenceEvents) {
messageBrokerService.getProducerTemplate().sendBodyAndHeader( messageBrokerService.getProducerTemplate().sendBodyAndHeader(
PersistenceEvent.PERSISTENCE_EVENT_TOPIC, PersistenceEvent.PERSISTENCE_TOPIC,
ExchangePattern.InOnly, ExchangePattern.InOnly,
persistenceEvent, persistenceEvent,
PersistenceEvent.HEADER_ENTITY_TYPE, PersistenceEvent.HEADER_ENTITY_TYPE,
Expand Down
Expand Up @@ -37,7 +37,7 @@
import java.util.logging.Logger; import java.util.logging.Logger;


import static org.openremote.agent3.protocol.Protocol.SENSOR_TOPIC; import static org.openremote.agent3.protocol.Protocol.SENSOR_TOPIC;
import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_EVENT_TOPIC; import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForAssetType; import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForAssetType;
import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType; import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;
import static org.openremote.model.asset.AssetType.AGENT; import static org.openremote.model.asset.AssetType.AGENT;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void stop(Container container) throws Exception {
public void configure() throws Exception { public void configure() throws Exception {


// If any agent or thing was modified in the database, deploy the changes // If any agent or thing was modified in the database, deploy the changes
from(PERSISTENCE_EVENT_TOPIC) from(PERSISTENCE_TOPIC)
.filter(isPersistenceEventForEntityType(Asset.class)) .filter(isPersistenceEventForEntityType(Asset.class))
.process(exchange -> { .process(exchange -> {
PersistenceEvent persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class); PersistenceEvent persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class);
Expand Down Expand Up @@ -129,8 +129,9 @@ protected void deployThing(Asset thing, PersistenceEvent.Cause cause) {
LOG.fine("Deploy thing: " + thing); LOG.fine("Deploy thing: " + thing);
ThingAttributes thingAttributes = new ThingAttributes(thing); ThingAttributes thingAttributes = new ThingAttributes(thing);


// Linked attributes have a reference to an agent, and a protocol configuration attribute of that agent // Attributes grouped by protocol name
Map<String, List<ThingAttribute>> linkedAttributes = thingAttributes.getLinkedAttributes( Map<String, List<ThingAttribute>> linkedAttributes = thingAttributes.getLinkedAttributes(
// Linked attributes have a reference to an agent, and a protocol configuration attribute of that agent
assetService.getAgentLinkResolver() assetService.getAgentLinkResolver()
); );


Expand All @@ -148,7 +149,6 @@ protected void deployThing(Asset thing, PersistenceEvent.Cause cause) {
linkAttributes(thing, protocols, linkedAttributes); linkAttributes(thing, protocols, linkedAttributes);
break; break;
case DELETE: case DELETE:
// TODO: Are we sure that all attributes are captured here? What if someone modifies attributes and then clicks on "Delete"?
unlinkAttributes(thing, protocols, linkedAttributes); unlinkAttributes(thing, protocols, linkedAttributes);
break; break;
} }
Expand Down
Expand Up @@ -45,7 +45,7 @@
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;


import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_EVENT_TOPIC; import static org.openremote.container.persistence.PersistenceEvent.PERSISTENCE_TOPIC;
import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType; import static org.openremote.manager.server.asset.AssetPredicates.isPersistenceEventForEntityType;
import static org.openremote.manager.server.event.EventPredicates.isEventType; import static org.openremote.manager.server.event.EventPredicates.isEventType;
import static org.openremote.model.asset.AssetType.AGENT; import static org.openremote.model.asset.AssetType.AGENT;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void configure() throws Exception {
); );
}); });


from(PERSISTENCE_EVENT_TOPIC) from(PERSISTENCE_TOPIC)
.filter(isPersistenceEventForEntityType(Asset.class)) .filter(isPersistenceEventForEntityType(Asset.class))
.process(exchange -> { .process(exchange -> {
PersistenceEvent persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class); PersistenceEvent persistenceEvent = exchange.getIn().getBody(PersistenceEvent.class);
Expand Down
3 changes: 1 addition & 2 deletions shared/src/main/java/org/openremote/model/asset/Asset.java
Expand Up @@ -20,7 +20,6 @@
package org.openremote.model.asset; package org.openremote.model.asset;


import elemental.json.JsonObject; import elemental.json.JsonObject;
import org.openremote.Constants;


import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
Expand All @@ -34,7 +33,7 @@
* The main model class of this software. * The main model class of this software.
* <p> * <p>
* An asset is an identifiable item in a composite relationship with other assets. This tree * An asset is an identifiable item in a composite relationship with other assets. This tree
* of assets can managed through a <code>null</code> {@link #parentId} property for root * of assets can be managed through a <code>null</code> {@link #parentId} property for root
* items, and a valid parent identifier for sub-items. * items, and a valid parent identifier for sub-items.
* <p> * <p>
* Each asset has dynamically typed optional attributes with an underlying * Each asset has dynamically typed optional attributes with an underlying
Expand Down
Expand Up @@ -83,6 +83,10 @@ public enum AssetType {


AGENT("urn:openremote:asset:agent", true, null), AGENT("urn:openremote:asset:agent", true, null),


/**
* When a Thing asset is modified (created, updated, deleted), its attributes are examined
* and linked to and unlinked from the configured Protocol.
*/
THING("urn:openremote:asset:thing", true, null); THING("urn:openremote:asset:thing", true, null);


final protected String value; final protected String value;
Expand Down

0 comments on commit 399d5d7

Please sign in to comment.