X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fstatisticsmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fstatisticsmanager%2Finternal%2FStatisticsManager.java;h=57dfa91b964956e68336673debbca76288d5a00d;hp=f5c13b61053ee5eaaa7eab5594608cd3da4ce5d7;hb=cadd31f02f414c8f62ab0919d1966ec1fec8ebe0;hpb=eed57e2b0afd50823bc882123b6cbac04bcc48d9 diff --git a/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java index f5c13b6105..57dfa91b96 100644 --- a/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java +++ b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java @@ -167,20 +167,32 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen * Function called after registering the service in OSGi service registry. */ void started(){ - //retrieve current statistics so we don't have to wait for next refresh + // Retrieve current statistics so we don't have to wait for next refresh ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance( ISwitchManager.class, container.getName(), this); - if (reader != null && switchManager != null) { + if ((reader != null) && (switchManager != null)) { Set nodeSet = switchManager.getNodes(); for (Node node : nodeSet) { - flowStatistics.put(node, reader.readAllFlows(node)); - descriptionStatistics.put(node, reader.readDescription(node)); - tableStatistics.put(node, reader.readNodeTable(node)); - nodeConnectorStatistics.put(node, reader.readNodeConnectors(node)); + List flows = reader.readAllFlows(node); + if (flows != null) { + flowStatistics.put(node, flows); + } + NodeDescription descr = reader.readDescription(node); + if (descr != null) { + descriptionStatistics.put(node, descr); + } + List tableStats = reader.readNodeTable(node); + if (tableStats != null) { + tableStatistics.put(node, tableStats); + } + List ncStats = reader.readNodeConnectors(node); + if (ncStats != null) { + nodeConnectorStatistics.put(node, ncStats); + } } } else { - log.warn("Failed to retrieve current statistics. Statistics will not be immidiately available!"); + log.trace("Failed to retrieve current statistics. Statistics will not be immediately available!"); } } @@ -247,7 +259,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen } Node node; - //index FlowEntries' flows by node so we don't traverse entire flow list for each flowEntry + // Index FlowEntries' flows by node so we don't traverse entire flow list for each flowEntry Map> index = new HashMap>(); for (FlowEntry flowEntry : flowList) { node = flowEntry.getNode(); @@ -256,7 +268,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen index.put(node, set); } - //iterate over flows per indexed node and add to output + // Iterate over flows per indexed node and add to output for (Entry> indexEntry : index.entrySet()) { node = indexEntry.getKey(); List flowsPerNode = flowStatistics.get(node); @@ -356,27 +368,40 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen @Override public void nodeFlowStatisticsUpdated(Node node, List flowStatsList) { - this.flowStatistics.put(node, flowStatsList); + List currentStat = this.flowStatistics.get(node); + // Update cache only if changed to avoid unnecessary cache sync operations + if (! flowStatsList.equals(currentStat)){ + this.flowStatistics.put(node, flowStatsList); + } } @Override public void nodeConnectorStatisticsUpdated(Node node, List ncStatsList) { - this.nodeConnectorStatistics.put(node, ncStatsList); + List currentStat = this.nodeConnectorStatistics.get(node); + if (! ncStatsList.equals(currentStat)){ + this.nodeConnectorStatistics.put(node, ncStatsList); + } } @Override public void nodeTableStatisticsUpdated(Node node, List tableStatsList) { - this.tableStatistics.put(node, tableStatsList); + List currentStat = this.tableStatistics.get(node); + if (! tableStatsList.equals(currentStat)) { + this.tableStatistics.put(node, tableStatsList); + } } @Override public void descriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) { - this.descriptionStatistics.put(node, nodeDescription); + NodeDescription currentDesc = this.descriptionStatistics.get(node); + if (! nodeDescription.equals(currentDesc)){ + this.descriptionStatistics.put(node, nodeDescription); + } } @Override public void updateNode(Node node, UpdateType type, Set props) { - //if node is removed, remove stats mappings + // If node is removed, clean up stats mappings if (type == UpdateType.REMOVED) { flowStatistics.remove(node); nodeConnectorStatistics.remove(node); @@ -387,6 +412,6 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen @Override public void updateNodeConnector(NodeConnector nodeConnector, UpdateType type, Set props) { - // not interested in this update + // Not interested in this update } }