- @Override
- public void connectedNodeRegistration(final InstanceIdentifier<Node> nodeIdent,
- final List<StatCapabTypes> statTypes, final Short nrOfSwitchTables) {
- for (final StatPermCollector collector : statCollectors) {
- if (collector.connectedNodeRegistration(nodeIdent, statTypes, nrOfSwitchTables)) {
- return;
- }
- }
- synchronized (statCollectorLock) {
- for (final StatPermCollector collector : statCollectors) {
- if (collector.connectedNodeRegistration(nodeIdent, statTypes, nrOfSwitchTables)) {
- return;
- }
- }
- final StatPermCollectorImpl newCollector = new StatPermCollectorImpl(this,
- statManagerConfig.getMinRequestNetMonitorInterval(), statCollectors.size() + 1,
- statManagerConfig.getMaxNodesForCollector());
- final List<StatPermCollector> statCollectorsNew = new ArrayList<>(statCollectors);
- newCollector.connectedNodeRegistration(nodeIdent, statTypes, nrOfSwitchTables);
- statCollectorsNew.add(newCollector);
- statCollectors = Collections.unmodifiableList(statCollectorsNew);
- }
- }
+ @Override
+ public void connectedNodeRegistration(final InstanceIdentifier<Node> nodeIdent,
+ final List<StatCapabTypes> statTypes, final Short nrOfSwitchTables) {
+
+
+ Pair<StatPermCollector, UUID> collectorUUIDPair = nodeCollectorMap.get(nodeIdent);
+ if (collectorUUIDPair == null) {
+ // no collector contains this node,
+ // check if one of the collectors can accommodate it
+ // if no then add a new collector
+
+ synchronized(statCollectorLock) {
+ for (int i = statCollectors.size() - 1; i >= 0; i--) {
+ // start from back of the list as most likely previous ones might be full
+ final StatPermCollector aCollector = statCollectors.get(i);
+ if (aCollector.connectedNodeRegistration(nodeIdent, statTypes, nrOfSwitchTables)) {
+ // if the collector returns true after adding node, then return
+ nodeCollectorMap.put(nodeIdent, new Pair(aCollector, UUID.randomUUID()));
+ LOG.debug("NodeAdded: Num Nodes Registered with StatisticsManager:{}",
+ numNodesBeingCollected.incrementAndGet());
+ return;
+ }
+ }
+ // no collector was able to add this node
+ LOG.info("No existing collector found for new node. Creating a new collector for {}", nodeIdent);
+ final StatPermCollectorImpl newCollector = new StatPermCollectorImpl(this,
+ statManagerConfig.getMinRequestNetMonitorInterval(), statCollectors.size() + 1,
+ statManagerConfig.getMaxNodesForCollector());
+
+ final List<StatPermCollector> statCollectorsNew = new ArrayList<>(statCollectors);
+ statCollectorsNew.add(newCollector);
+ statCollectors = Collections.unmodifiableList(statCollectorsNew);
+ nodeCollectorMap.put(nodeIdent, new Pair(newCollector, UUID.randomUUID()));
+ LOG.debug("NodeAdded: Num Nodes Registered with StatisticsManager:{}", numNodesBeingCollected.incrementAndGet());
+
+ newCollector.connectedNodeRegistration(nodeIdent, statTypes, nrOfSwitchTables);
+ }
+
+
+ } else {
+ // add to the collector, even if it rejects it.
+ collectorUUIDPair.getLeft().connectedNodeRegistration(nodeIdent, statTypes, nrOfSwitchTables);
+ }
+ }