Class WebsocketAgentProtocol
java.lang.Object
org.openremote.agent.protocol.AbstractProtocol<U,X>
org.openremote.agent.protocol.io.AbstractIOClientProtocol<T,U,V,W,X>
org.openremote.agent.protocol.io.AbstractNettyIOClientProtocol<WebsocketAgentProtocol,WebsocketAgent,String,WebsocketIOClient<String>,WebsocketAgentLink>
org.openremote.agent.protocol.websocket.WebsocketAgentProtocol
- All Implemented Interfaces:
org.openremote.model.asset.agent.Protocol<WebsocketAgent>
public class WebsocketAgentProtocol
extends AbstractNettyIOClientProtocol<WebsocketAgentProtocol,WebsocketAgent,String,WebsocketIOClient<String>,WebsocketAgentLink>
This is a generic
Protocol for communicating with a Websocket server
using String based messages.
Protocol Specifics
When the websocket connection is established it is possible to subscribe to events by specifying theWebsocketAgent.CONNECT_SUBSCRIPTIONS on the WebsocketAgent or
WebsocketAgentLink.getWebsocketSubscriptions() on linked Attributes; a
subscription can be a message sent over the websocket or a HTTP REST API call.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final Stringprotected final List<org.openremote.model.util.Pair<org.openremote.model.attribute.AttributeRef,Consumer<String>>> protected static final org.jboss.resteasy.client.jaxrs.ResteasyClientFields inherited from class org.openremote.agent.protocol.io.AbstractIOClientProtocol
clientFields inherited from class org.openremote.agent.protocol.AbstractProtocol
agent, assetService, datapointService, dynamicAttributes, executorService, linkedAttributes, messageBrokerContext, predictedDatapointService, producerTemplate, timerServiceFields inherited from interface org.openremote.model.asset.agent.Protocol
ACTUATOR_TOPIC, ACTUATOR_TOPIC_TARGET_PROTOCOL, DYNAMIC_TIME_PLACEHOLDER_REGEXP, DYNAMIC_VALUE_PLACEHOLDER, DYNAMIC_VALUE_PLACEHOLDER_REGEXP, SENSOR_QUEUE, SENSOR_QUEUE_SOURCE_PROTOCOL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAttributeConnectedTask(org.openremote.model.attribute.AttributeRef attributeRef, Runnable task) protected voidprotected StringcreateWriteMessage(org.openremote.model.attribute.Attribute<?> attribute, WebsocketAgentLink agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) Generate the actual message to send to theIOClientfor thisAttributeEventprotected WebsocketIOClient<String>Should return an instance ofIOClientfor the linkedAgent.protected voiddoLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, WebsocketAgentLink agentLink) Link anAttributeto its linkedAgent.protected voiddoStop(org.openremote.model.Container container) Stop this protocol instanceprotected voiddoSubscription(Map<String, List<String>> headers, WebsocketSubscription subscription) protected voiddoSubscriptions(Map<String, List<String>> headers, WebsocketSubscription[] subscriptions) protected voiddoUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, WebsocketAgentLink agentLink) Unlink anAttributefrom its linkedAgent.protected Supplier<io.netty.channel.ChannelHandler[]>Gets the NettyChannelHandlers for the IO clientGet the name for this protocolprotected voidprotected voidonMessageReceived(String message) Called when theIOClientreceives a message from the serverprotected voidsetConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) Methods inherited from class org.openremote.agent.protocol.io.AbstractNettyIOClientProtocol
createIoClientMethods inherited from class org.openremote.agent.protocol.io.AbstractIOClientProtocol
doLinkedAttributeWrite, doStart, getGenericStringEncodersAndDecoders, getProtocolInstanceUri, onConnectionStatusChangedMethods inherited from class org.openremote.agent.protocol.AbstractProtocol
getAgent, getLinkedAttributes, linkAttribute, processLinkedAttributeWrite, sendAttributeEvent, sendAttributeEvent, start, stop, toString, unlinkAttribute, updateAgentAttribute, updateLinkedAttribute, updateLinkedAttributeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openremote.model.asset.agent.Protocol
prefixLogMessage
-
Field Details
-
PROTOCOL_DISPLAY_NAME
- See Also:
-
CONNECTED_SEND_DELAY_MILLIS
public static final int CONNECTED_SEND_DELAY_MILLIS- See Also:
-
resteasyClient
protected static final org.jboss.resteasy.client.jaxrs.ResteasyClient resteasyClient -
protocolConnectedTasks
-
attributeConnectedTasks
-
clientHeaders
-
protocolMessageConsumers
-
-
Constructor Details
-
WebsocketAgentProtocol
-
-
Method Details
-
getProtocolName
Description copied from interface:org.openremote.model.asset.agent.ProtocolGet the name for this protocol -
doStop
Description copied from class:AbstractProtocolStop this protocol instance- Overrides:
doStopin classAbstractIOClientProtocol<WebsocketAgentProtocol,WebsocketAgent, String, WebsocketIOClient<String>, WebsocketAgentLink> - Throws:
Exception
-
getEncoderDecoderProvider
Description copied from class:AbstractNettyIOClientProtocolGets the NettyChannelHandlers for the IO client -
onMessageReceived
Description copied from class:AbstractIOClientProtocolCalled when theIOClientreceives a message from the server- Specified by:
onMessageReceivedin classAbstractIOClientProtocol<WebsocketAgentProtocol,WebsocketAgent, String, WebsocketIOClient<String>, WebsocketAgentLink>
-
createWriteMessage
protected String createWriteMessage(org.openremote.model.attribute.Attribute<?> attribute, WebsocketAgentLink agentLink, org.openremote.model.attribute.AttributeEvent event, Object processedValue) Description copied from class:AbstractIOClientProtocolGenerate the actual message to send to theIOClientfor thisAttributeEvent- Specified by:
createWriteMessagein classAbstractIOClientProtocol<WebsocketAgentProtocol,WebsocketAgent, String, WebsocketIOClient<String>, WebsocketAgentLink>
-
doCreateIoClient
Description copied from class:AbstractIOClientProtocolShould return an instance ofIOClientfor the linkedAgent.- Specified by:
doCreateIoClientin classAbstractIOClientProtocol<WebsocketAgentProtocol,WebsocketAgent, String, WebsocketIOClient<String>, WebsocketAgentLink> - Throws:
Exception
-
setConnectionStatus
protected void setConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus connectionStatus) - Overrides:
setConnectionStatusin classAbstractProtocol<WebsocketAgent,WebsocketAgentLink>
-
doLinkAttribute
protected void doLinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, WebsocketAgentLink agentLink) Description copied from class:AbstractProtocolLink anAttributeto its linkedAgent.- Specified by:
doLinkAttributein classAbstractProtocol<WebsocketAgent,WebsocketAgentLink>
-
doUnlinkAttribute
protected void doUnlinkAttribute(String assetId, org.openremote.model.attribute.Attribute<?> attribute, WebsocketAgentLink agentLink) Description copied from class:AbstractProtocolUnlink anAttributefrom its linkedAgent.- Specified by:
doUnlinkAttributein classAbstractProtocol<WebsocketAgent,WebsocketAgentLink>
-
onConnected
protected void onConnected() -
addProtocolConnectedTask
-
addAttributeConnectedTask
protected void addAttributeConnectedTask(org.openremote.model.attribute.AttributeRef attributeRef, Runnable task) -
doSubscriptions
protected void doSubscriptions(Map<String, List<String>> headers, WebsocketSubscription[] subscriptions) -
doSubscription
-