Package org.openremote.agent.protocol
Class AbstractProtocol<T extends org.openremote.model.asset.agent.Agent<T,?,U>,U extends org.openremote.model.asset.agent.AgentLink<?>>
java.lang.Object
org.openremote.agent.protocol.AbstractProtocol<T,U>
- All Implemented Interfaces:
org.openremote.model.asset.agent.Protocol<T>
- Direct Known Subclasses:
AbstractHTTPServerProtocol
,AbstractIOClientProtocol
,AbstractMailProtocol
,AbstractTCPServerProtocol
,AbstractVelbusProtocol
,BluetoothMeshProtocol
,HTTPProtocol
,KNXProtocol
,SimulatorProtocol
,SNMPProtocol
,StorageSimulatorProtocol
,TradfriProtocol
,ZWaveProtocol
public abstract class AbstractProtocol<T extends org.openremote.model.asset.agent.Agent<T,?,U>,U extends org.openremote.model.asset.agent.AgentLink<?>>
extends Object
implements org.openremote.model.asset.agent.Protocol<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected T
protected org.openremote.model.protocol.ProtocolAssetService
protected ProtocolDatapointService
protected final Set<org.openremote.model.attribute.AttributeRef>
protected ExecutorService
protected final Map<org.openremote.model.attribute.AttributeRef,
org.openremote.model.attribute.Attribute<?>> protected org.apache.camel.impl.DefaultCamelContext
protected ProtocolPredictedDatapointService
protected final Object
protected org.apache.camel.ProducerTemplate
protected ScheduledExecutorService
protected org.openremote.container.timer.TimerService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
doLinkAttribute
(String assetId, org.openremote.model.attribute.Attribute<?> attribute, U agentLink) Link anAttribute
to its linkedAgent
.protected abstract void
doLinkedAttributeWrite
(U agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) An Attribute event (write) has been requested for an attribute linked to this protocol.protected abstract void
doStart
(org.openremote.model.Container container) Start this protocol instanceprotected abstract void
doStop
(org.openremote.model.Container container) Stop this protocol instanceprotected abstract void
doUnlinkAttribute
(String assetId, org.openremote.model.attribute.Attribute<?> attribute, U agentLink) Unlink anAttribute
from its linkedAgent
.getAgent()
Get theAgent
associated with this protocol instance.Map<org.openremote.model.attribute.AttributeRef,
org.openremote.model.attribute.Attribute<?>> Get list ofAttribute
s currently linked to this protocol instance grouped byAsset
IDfinal void
linkAttribute
(String assetId, org.openremote.model.attribute.Attribute<?> attribute) Links anAttribute
to its' agent; the agent would have been connected before this call.boolean
onAgentAttributeChanged
(org.openremote.model.attribute.AttributeEvent event) Called when one of the associatedAgent
'sAttribute
s are updated; the implementation can decide if it wants to request the protocol instance to be re-created thus simplifying handling of config changes.void
processLinkedAttributeWrite
(org.openremote.model.attribute.AttributeEvent event) An Attribute event (write) has been requested for an attribute linked to this protocol; implementations should handle multithreaded requests or use some sort of synchronisation for thread safety.protected final void
sendAttributeEvent
(org.openremote.model.attribute.AttributeEvent event) Send an arbitraryAttributeEvent
through the processing chain.protected final void
sendAttributeEvent
(org.openremote.model.attribute.AttributeState state) Send an arbitraryAttributeState
through the processing chain using the current system time as the timestamp.void
setAssetService
(org.openremote.model.protocol.ProtocolAssetService assetService) Called by instantiator during instantiation to allow theProtocol
to interact withAsset
s andAttribute
s.protected void
setConnectionStatus
(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) void
start
(org.openremote.model.Container container) Called before any calls toProtocol.linkAttribute(java.lang.String, org.openremote.model.attribute.Attribute<?>)
to allow the protocol to perform required tasks withContainerService
s (e.g.final void
stop
(org.openremote.model.Container container) Called once all linked attributes have been unlinked viaProtocol.unlinkAttribute(java.lang.String, org.openremote.model.attribute.Attribute<?>)
to allow the protocol to perform required tasks withContainerService
s e.g.toString()
final void
unlinkAttribute
(String assetId, org.openremote.model.attribute.Attribute<?> attribute) Un-links anAttribute
from its' agent; the agent will still be connected during this call.final void
updateLinkedAttribute
(org.openremote.model.attribute.AttributeRef attributeRef, Object value) Update the value of a linkedAttribute
linked to thisProtocol
; call this to publish new sensor values.final void
updateLinkedAttribute
(org.openremote.model.attribute.AttributeRef attributeRef, Object value, long timestamp) Update the value of a linkedAttribute
linked to thisProtocol
; call this to publish new sensor values.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.openremote.model.asset.agent.Protocol
getProtocolInstanceUri, getProtocolName, prefixLogMessage
-
Field Details
-
linkedAttributes
protected final Map<org.openremote.model.attribute.AttributeRef,org.openremote.model.attribute.Attribute<?>> linkedAttributes -
dynamicAttributes
-
messageBrokerContext
protected org.apache.camel.impl.DefaultCamelContext messageBrokerContext -
producerTemplate
protected org.apache.camel.ProducerTemplate producerTemplate -
timerService
protected org.openremote.container.timer.TimerService timerService -
executorService
-
scheduledExecutorService
-
assetService
protected org.openremote.model.protocol.ProtocolAssetService assetService -
predictedDatapointService
-
datapointService
-
agent
-
processorLock
-
-
Constructor Details
-
AbstractProtocol
-
-
Method Details
-
setAssetService
public void setAssetService(org.openremote.model.protocol.ProtocolAssetService assetService) Description copied from interface:org.openremote.model.asset.agent.Protocol
Called by instantiator during instantiation to allow theProtocol
to interact withAsset
s andAttribute
s. -
start
Description copied from interface:org.openremote.model.asset.agent.Protocol
Called before any calls toProtocol.linkAttribute(java.lang.String, org.openremote.model.attribute.Attribute<?>)
to allow the protocol to perform required tasks withContainerService
s (e.g. register Camel routes). The protocol instance should validate the settings defined in the associatedAgent
; but whether or not the protocol establishes a connection/ fully initialises at this time is up to the protocol implementation, it could be desirable to wait untilProtocol.linkAttribute(java.lang.String, org.openremote.model.attribute.Attribute<?>)
is called for the first time, or it could be a connectionless protocol. If there is a configuration issue etc. then an appropriate exception should be thrown and suitable logs made. -
stop
public final void stop(org.openremote.model.Container container) Description copied from interface:org.openremote.model.asset.agent.Protocol
Called once all linked attributes have been unlinked viaProtocol.unlinkAttribute(java.lang.String, org.openremote.model.attribute.Attribute<?>)
to allow the protocol to perform required tasks withContainerService
s e.g. remove Camel routes, destroy/cleanup resources etc. -
setConnectionStatus
protected void setConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) -
linkAttribute
public final void linkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute) throws Exception Description copied from interface:org.openremote.model.asset.agent.Protocol
Links anAttribute
to its' agent; the agent would have been connected before this call. This is called when the agent is connected or when the attribute has been modified and re-linked.If the attribute is not valid for this protocol then it is up to the protocol to log the issue and return false.
Attributes are linked to an agent via an
MetaItemType.AGENT_LINK
meta item. -
unlinkAttribute
public final void unlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute) throws Exception Description copied from interface:org.openremote.model.asset.agent.Protocol
Un-links anAttribute
from its' agent; the agent will still be connected during this call. This is called whenever the attribute is modified or removed or when the agent is modified or removed. -
getAgent
Description copied from interface:org.openremote.model.asset.agent.Protocol
Get theAgent
associated with this protocol instance. -
getLinkedAttributes
public Map<org.openremote.model.attribute.AttributeRef,org.openremote.model.attribute.Attribute<?>> getLinkedAttributes()Description copied from interface:org.openremote.model.asset.agent.Protocol
Get list ofAttribute
s currently linked to this protocol instance grouped byAsset
ID -
processLinkedAttributeWrite
public void processLinkedAttributeWrite(org.openremote.model.attribute.AttributeEvent event) Description copied from interface:org.openremote.model.asset.agent.Protocol
An Attribute event (write) has been requested for an attribute linked to this protocol; implementations should handle multithreaded requests or use some sort of synchronisation for thread safety. TheAttributeEvent
will be enriched with data about the relating asset and attribute. -
sendAttributeEvent
protected final void sendAttributeEvent(org.openremote.model.attribute.AttributeState state) Send an arbitraryAttributeState
through the processing chain using the current system time as the timestamp. UseupdateLinkedAttribute(org.openremote.model.attribute.AttributeRef, java.lang.Object, long)
to publish new sensor values, which performs additional verification and uses a different messaging queue. -
sendAttributeEvent
protected final void sendAttributeEvent(org.openremote.model.attribute.AttributeEvent event) Send an arbitraryAttributeEvent
through the processing chain. UseupdateLinkedAttribute(org.openremote.model.attribute.AttributeRef, java.lang.Object, long)
to publish new sensor values, which performs additional verification and uses a different messaging queue. -
updateLinkedAttribute
public final void updateLinkedAttribute(org.openremote.model.attribute.AttributeRef attributeRef, Object value, long timestamp) Description copied from interface:org.openremote.model.asset.agent.Protocol
Update the value of a linkedAttribute
linked to thisProtocol
; call this to publish new sensor values. Implementors are responsible for ensuring the requestedAttribute
is actually linked to thisProtocol
. -
updateLinkedAttribute
public final void updateLinkedAttribute(org.openremote.model.attribute.AttributeRef attributeRef, Object value) Description copied from interface:org.openremote.model.asset.agent.Protocol
Update the value of a linkedAttribute
linked to thisProtocol
; call this to publish new sensor values. Implementors are responsible for ensuring the requestedAttribute
is actually linked to thisProtocol
. -
onAgentAttributeChanged
public boolean onAgentAttributeChanged(org.openremote.model.attribute.AttributeEvent event) Description copied from interface:org.openremote.model.asset.agent.Protocol
Called when one of the associatedAgent
'sAttribute
s are updated; the implementation can decide if it wants to request the protocol instance to be re-created thus simplifying handling of config changes. -
doStart
Start this protocol instance- Throws:
Exception
-
doStop
Stop this protocol instance- Throws:
Exception
-
toString
-
doLinkAttribute
protected abstract void doLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, U agentLink) throws RuntimeException Link anAttribute
to its linkedAgent
.- Throws:
RuntimeException
-
doUnlinkAttribute
protected abstract void doUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, U agentLink) Unlink anAttribute
from its linkedAgent
. -
doLinkedAttributeWrite
protected abstract void doLinkedAttributeWrite(U agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) An Attribute event (write) has been requested for an attribute linked to this protocol. The processedValue is the resulting value after applying standard outbound value processing (seeProtocolUtil.doOutboundValueProcessing(org.openremote.model.attribute.AttributeRef, org.openremote.model.asset.agent.AgentLink<?>, java.lang.Object, boolean, java.time.Instant)
). Protocol implementations should generally use the processedValue but may also choose to use the original value for some purpose if required.
-