100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Fix for duplicate attribute linking in AgentService
Rich Turner6a6139bad619
diff --git a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.javaindex c6585702e..692ab3f49 100644--- a/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/agent/AgentService.java@@ -77,6 +77,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Consprotected MessageBrokerService messageBrokerService;protected final Map<AttributeRef, Pair<AssetAttribute, ConnectionStatus>> protocolConfigurations = new HashMap<>();protected final Map<String, Protocol> protocols = new HashMap<>();+ protected final List<AttributeRef> linkedAttributes = new ArrayList<>();@Overridepublic void init(Container container) throws Exception {@@ -296,7 +297,10 @@ public class AgentService extends RouteBuilder implements ContainerService, Cons// so need to check that all protocol configs exist - any that don't we will exclude here// and handle in agent insert- // Link any AGENT_LINK attributes to the referenced protocol+ // If an agent insert just occurred then we will end up trying to link the attribute again+ // so we keep track of linked attributes to avoid this++ // Link any AGENT_LINK attributes to their referenced protocolMap<AssetAttribute, List<AssetAttribute>> groupedAgentLinksAttributes =getGroupedAgentLinkAttributes(asset.getAttributesStream(),@@ -517,6 +521,11 @@ public class AgentService extends RouteBuilder implements ContainerService, Consreturn;}+ synchronized (linkedAttributes) {+ attributes.removeIf(attr -> linkedAttributes.contains(attr.getReferenceOrThrow()));+ linkedAttributes.addAll(attributes.stream().map(AssetAttribute::getReferenceOrThrow).collect(Collectors.toList()));+ }+try {LOG.finest("Linking protocol attributes to: " + protocol.getProtocolName());protocol.linkAttributes(attributes, protocolConfiguration);@@ -535,6 +544,11 @@ public class AgentService extends RouteBuilder implements ContainerService, Consreturn;}+ synchronized (linkedAttributes) {+ attributes.removeIf(attr -> !linkedAttributes.contains(attr.getReferenceOrThrow()));+ linkedAttributes.removeAll(attributes.stream().map(AssetAttribute::getReferenceOrThrow).collect(Collectors.toList()));+ }+try {LOG.finest("Unlinking protocol attributes from: " + protocol.getProtocolName());protocol.unlinkAttributes(attributes, protocolConfiguration);