+ private void updateContainerMap(List<String> containers, NodeConnector p) {
+ if (containers.isEmpty()) {
+ // Do cleanup to reduce memory footprint if no
+ // elements to be tracked
+ this.containerMap.remove(p);
+ } else {
+ this.containerMap.put(p, containers);
+ }
+ }
+
+ /**
+ * From a given edge map, retrieve the edge sourced by the port and update
+ * the local cache in the container
+ *
+ * @param container
+ * the container name
+ * @param nodeConnector
+ * the node connector
+ * @param edges
+ * the given edge map
+ * @return the found edge
+ */
+ private Edge addEdge(String container, NodeConnector nodeConnector,
+ Map<NodeConnector, Pair<Edge, Set<Property>>> edges) {
+ logger.debug("Search edge sourced by port {} in container {}", nodeConnector, container);
+
+ // Retrieve the associated edge
+ Pair<Edge, Set<Property>> edgeProps = edges.get(nodeConnector);
+ if (edgeProps == null) {
+ logger.debug("edgePros is null for port {} in container {}", nodeConnector, container);
+ return null;
+ }
+
+ Edge edge = edgeProps.getLeft();
+ if (edge == null) {
+ logger.debug("edge is null for port {} in container {}", nodeConnector, container);
+ return null;
+ }
+
+ // Make sure the peer port is in the same container
+ NodeConnector peerConnector = edge.getHeadNodeConnector();
+ List<String> containers = this.containerMap.get(peerConnector);
+ if ((containers == null) || !containers.contains(container)) {
+ logger.debug("peer port {} of edge {} is not part of the container {}", new Object[] { peerConnector, edge,
+ container });
+ return null;
+ }
+
+ // Update the local cache
+ updateLocalEdgeMap(container, edge, UpdateType.ADDED, edgeProps.getRight());
+ logger.debug("Added edge {} to local cache in container {}", edge, container);
+
+ return edge;
+ }
+
+ private void addNodeConnector(String container,
+ NodeConnector nodeConnector) {
+ // Use the global edge map for the newly added port in a container
+ Map<NodeConnector, Pair<Edge, Set<Property>>> globalEdgeMap = edgeMap.get(GlobalConstants.DEFAULT
+ .toString());
+ if (globalEdgeMap == null) {
+ return;
+ }
+
+ // Get the edge and update local cache in the container
+ Edge edge1, edge2;
+ edge1 = addEdge(container, nodeConnector, globalEdgeMap);
+ if (edge1 == null) {
+ return;
+ }
+
+ // Get the edge in reverse direction and update local cache in the container
+ NodeConnector peerConnector = edge1.getHeadNodeConnector();
+ edge2 = addEdge(container, peerConnector, globalEdgeMap);
+
+ // Send notification upwards in one shot
+ List<TopoEdgeUpdate> teuList = new ArrayList<TopoEdgeUpdate>();
+ teuList.add(new TopoEdgeUpdate(edge1, null, UpdateType.ADDED));
+ logger.debug("Notify edge1: {} in container {}", edge1, container);
+ if (edge2 != null) {
+ teuList.add(new TopoEdgeUpdate(edge2, null, UpdateType.ADDED));
+ logger.debug("Notify edge2: {} in container {}", edge2, container);
+ }
+ notifyEdge(container, teuList);
+ }
+