Class AgentService
- All Implemented Interfaces:
org.apache.camel.builder.ModelRoutesBuilder,org.apache.camel.CamelContextAware,org.apache.camel.Ordered,org.apache.camel.RoutesBuilder,org.apache.camel.spi.HasCamelContext,org.apache.camel.spi.ResourceAware,org.openremote.model.ContainerService
Protocol instances when an Attribute of the associated Agent is modified
either via Asset CRUD or just via an AttributeEvent.
Only an AttributeEvent for an Attribute containing a
MetaItemType.AGENT_LINK MetaItem will be intercepted here and passed to
the associated Protocol instance for processing; the event will not be committed to the DB and it is up to
the Protocol to generate a new AttributeEvent to signal that the action has been successfully handled.
Any AttributeEvent that originates from an Agent Protocol will not be consumed by the source
Protocol when it passes back through this service; this is to prevent infinite loops.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Objectprotected AssetProcessingServiceprotected AssetStorageServiceprotected final Map<String, Set<Consumer<org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>>>>> protected ClientEventServiceprotected org.openremote.model.Containerprotected ExecutorServiceprotected GatewayServiceprotected booleanstatic final intFields inherited from class org.apache.camel.builder.RouteBuilder
logFields inherited from interface org.openremote.model.ContainerService
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITYFields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.openremote.model.asset.agent.Agent<?, ?, ?> addAgent(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) voidprotected voiddeployAgent(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) Deploy theAgentby creating a protocol instance, starting it and linking all attributesprotected voiddoAgentInit(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) doProtocolAssetDiscovery(org.openremote.model.asset.agent.Agent<?, ?, ?> agent, Consumer<org.openremote.model.asset.AssetTreeNode[]> onDiscovered) doProtocolAssetImport(org.openremote.model.asset.agent.Agent<?, ?, ?> agent, byte[] fileData, Consumer<org.openremote.model.asset.AssetTreeNode[]> onDiscovered) doProtocolInstanceDiscovery(String parentId, Class<? extends org.openremote.model.protocol.ProtocolInstanceDiscovery> instanceDiscoveryProviderClass, Consumer<org.openremote.model.asset.agent.Agent<?, ?, ?>[]> onDiscovered) org.openremote.model.asset.agent.Agent<?, ?, ?> protected Map<org.openremote.model.asset.agent.Agent<?, ?, ?>, List<org.openremote.model.attribute.Attribute<?>>> getGroupedAgentLinkAttributes(Stream<org.openremote.model.attribute.Attribute<?>> attributes, Predicate<org.openremote.model.attribute.Attribute<?>> filter) Gets all agent link attributes and their linked agent and groups them by agentintorg.openremote.model.asset.agent.Protocol<?> getProtocolInstance(String agentId) org.openremote.model.asset.agent.Protocol<?> getProtocolInstance(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) voidinit(org.openremote.model.Container container) booleanprotected voidlinkAttributes(org.openremote.model.asset.agent.Agent<?, ?, ?> agent, String assetId, Collection<org.openremote.model.attribute.Attribute<?>> attributes) protected voidnotifyAgentAncestor(org.openremote.model.asset.Asset<?> asset, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) protected voidnotifyChildAssetChange(String agentId, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> assetPersistenceEvent) protected voidokToContinueWithImportOrDiscovery(String agentId) protected voidonAgentAttributeEvent(org.openremote.model.attribute.AttributeEvent event) Called when anAttributeEventfor anAgentis broadcast on the client event bus (i.e.protected booleanonAttributeEventIntercepted(jakarta.persistence.EntityManager em, org.openremote.model.attribute.AttributeEvent event) Intercepts anyAttributeEventfor anAttributethat has anMetaItemType.AGENT_LINKMetaItemand passes it to theAgent'sProtocol.processLinkedAttributeWrite(org.openremote.model.attribute.AttributeEvent)method for handling.protected voidprocessAgentChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.agent.Agent<?, ?, ?>> persistenceEvent) Called when anAgentis modified in the DBprotected voidprocessAssetChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) Looks for new, modified and obsolete AGENT_LINK attributes and links / unlinks them with the protocolprotected booleanremoveAgent(String agentId) protected voidsendAttributeEvent(org.openremote.model.attribute.AttributeEvent event) voidstart(org.openremote.model.Container container) protected voidstartAgent(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) voidstop(org.openremote.model.Container container) toString()protected voidundeployAgent(String agentId) protected voidunlinkAttributes(String agentId, String assetId, List<org.openremote.model.attribute.Attribute<?>> attributes) Methods inherited from class org.apache.camel.builder.RouteBuilder
addLifecycleInterceptor, addRoutes, addRoutesToCamelContext, addTemplatedRoutesToCamelContext, bindToRegistry, bindToRegistry, checkInitialized, configuration, configureRest, configureRests, configureRoute, configureRouteConfiguration, configureRoutes, configureRouteTemplate, configureTemplatedRoute, customize, customize, dataFormat, errorHandler, errorHandler, expression, from, from, from, fromF, fromV, fromV, getBeans, getOrder, getResource, getRestCollection, getRestConfiguration, getRests, getRouteCollection, getRoutes, getRouteTemplateCollection, getTemplatedRouteCollection, initializeCamelContext, intercept, interceptFrom, interceptFrom, interceptSendToEndpoint, loadRoutesBuilder, loadRoutesBuilder, onCompletion, onException, onException, populateBeans, populateOrUpdateRoutes, populateRests, populateRoutes, populateRouteTemplates, populateTemplatedRoutes, populateTransformers, populateValidators, prepareModel, property, propertyInject, removeLifecycleInterceptor, rest, rest, restConfiguration, routeTemplate, setErrorHandlerFactory, setResource, setRestCollection, setRouteTemplateCollection, setTemplatedRouteCollection, templatedRoute, tokenizer, transformer, updateRoutesToCamelContext, validatorMethods inherited from class org.apache.camel.builder.BuilderSupport
body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, java, java, joor, joor, jq, jq, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, variable, xpath, xpath, xpath, xpath
-
Field Details
-
PRIORITY
public static final int PRIORITY- See Also:
-
assetProcessingService
-
assetStorageService
-
clientEventService
-
gatewayService
-
executorService
-
agentMap
-
agentDiscoveryImportFutureMap
-
protocolInstanceMap
-
childAssetSubscriptions
-
initDone
protected boolean initDone -
container
protected org.openremote.model.Container container -
agentLock
-
-
Constructor Details
-
AgentService
public AgentService()
-
-
Method Details
-
getPriority
public int getPriority()- Specified by:
getPriorityin interfaceorg.openremote.model.ContainerService
-
init
- Specified by:
initin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
start
- Specified by:
startin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
stop
- Specified by:
stopin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
configure
- Specified by:
configurein classorg.apache.camel.builder.RouteBuilder- Throws:
Exception
-
processAgentChange
protected void processAgentChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.agent.Agent<?, ?, ?>> persistenceEvent) Called when anAgentis modified in the DB -
deployAgent
protected void deployAgent(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) Deploy theAgentby creating a protocol instance, starting it and linking all attributes -
processAssetChange
protected void processAssetChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) Looks for new, modified and obsolete AGENT_LINK attributes and links / unlinks them with the protocol -
notifyAgentAncestor
protected void notifyAgentAncestor(org.openremote.model.asset.Asset<?> asset, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> persistenceEvent) -
sendAttributeEvent
protected void sendAttributeEvent(org.openremote.model.attribute.AttributeEvent event) -
doAgentInit
protected void doAgentInit(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) -
startAgent
protected void startAgent(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) -
undeployAgent
-
linkAttributes
protected void linkAttributes(org.openremote.model.asset.agent.Agent<?, ?, ?> agent, String assetId, Collection<org.openremote.model.attribute.Attribute<?>> attributes) -
unlinkAttributes
-
onAttributeEventIntercepted
protected boolean onAttributeEventIntercepted(jakarta.persistence.EntityManager em, org.openremote.model.attribute.AttributeEvent event) throws AssetProcessingException Intercepts anyAttributeEventfor anAttributethat has anMetaItemType.AGENT_LINKMetaItemand passes it to theAgent'sProtocol.processLinkedAttributeWrite(org.openremote.model.attribute.AttributeEvent)method for handling.If the
AttributeEventoriginated from theAgentthat theAttributeis linked to then it is not intercepted.- Throws:
AssetProcessingException
-
onAgentAttributeEvent
protected void onAgentAttributeEvent(org.openremote.model.attribute.AttributeEvent event) Called when anAttributeEventfor anAgentis broadcast on the client event bus (i.e. the attribute has been updated in the DB).We use this to try and react to agent changes in a generic way by re-initialising the agent to simplify each agent implementation.
-
getGroupedAgentLinkAttributes
protected Map<org.openremote.model.asset.agent.Agent<?,?, getGroupedAgentLinkAttributes?>, List<org.openremote.model.attribute.Attribute<?>>> (Stream<org.openremote.model.attribute.Attribute<?>> attributes, Predicate<org.openremote.model.attribute.Attribute<?>> filter) Gets all agent link attributes and their linked agent and groups them by agent -
toString
- Overrides:
toStringin classorg.apache.camel.builder.RouteBuilder
-
addAgent
protected org.openremote.model.asset.agent.Agent<?,?, addAgent?> (org.openremote.model.asset.agent.Agent<?, ?, ?> agent) -
removeAgent
-
getAgent
-
getAgents
-
getProtocolInstance
public org.openremote.model.asset.agent.Protocol<?> getProtocolInstance(org.openremote.model.asset.agent.Agent<?, ?, ?> agent) -
getProtocolInstance
-
notifyChildAssetChange
protected void notifyChildAssetChange(String agentId, org.openremote.model.PersistenceEvent<org.openremote.model.asset.Asset<?>> assetPersistenceEvent) -
isProtocolAssetDiscoveryOrImportRunning
-
doProtocolInstanceDiscovery
-
doProtocolAssetDiscovery
public Future<Void> doProtocolAssetDiscovery(org.openremote.model.asset.agent.Agent<?, ?, throws RuntimeException?> agent, Consumer<org.openremote.model.asset.AssetTreeNode[]> onDiscovered) - Throws:
RuntimeException
-
doProtocolAssetImport
public Future<Void> doProtocolAssetImport(org.openremote.model.asset.agent.Agent<?, ?, throws RuntimeException?> agent, byte[] fileData, Consumer<org.openremote.model.asset.AssetTreeNode[]> onDiscovered) - Throws:
RuntimeException
-
okToContinueWithImportOrDiscovery
-