X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fstatistics-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fstatistics%2Fmanager%2FStatisticsRequestScheduler.java;h=29a27e2bb2a2cdfc85c7b49eada243bdc9f8a531;hp=9ebfd6fd62f7b2ab8933d86a03a788b3154d2eb5;hb=c1362c86eb19e92e6c64d10099a45deb499c6db1;hpb=9d269c372a5d565101629cea6dad14a35a9e0591 diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsRequestScheduler.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsRequestScheduler.java index 9ebfd6fd62..29a27e2bb2 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsRequestScheduler.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsRequestScheduler.java @@ -18,12 +18,13 @@ import java.util.concurrent.TimeUnit; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction.DataTransactionListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Main responsibility of the class is to check the MD-SAL data store read/write - * transaction accumulation level and send statistics request if number of pending + * transaction accumulation level and send statistics request if number of pending * read/write transactions are zero. * @author avishnoi@in.ibm.com * @@ -35,21 +36,25 @@ public class StatisticsRequestScheduler implements DataTransactionListener { private final Timer timer = new Timer("request-monitor", true); // We need ordered retrieval, and O(1) contains operation - private final Map requestQueue = + private final Map requestQueue = Collections.synchronizedMap(new LinkedHashMap()); - + private Long PendingTransactions; - + private long lastRequestTime = System.nanoTime(); - + private static final long REQUEST_MONITOR_INTERVAL = 1000; - + private final TimerTask task = new TimerTask() { @Override public void run() { - long now = System.nanoTime(); - if(now > lastRequestTime+TimeUnit.MILLISECONDS.toNanos(REQUEST_MONITOR_INTERVAL)){ - requestStatistics(); + try{ + long now = System.nanoTime(); + if(now > lastRequestTime+TimeUnit.MILLISECONDS.toNanos(REQUEST_MONITOR_INTERVAL)){ + requestStatistics(); + } + }catch (IllegalArgumentException | IllegalStateException | NullPointerException e){ + srsLogger.warn("Exception occured while sending statistics request : {}",e); } } }; @@ -57,11 +62,24 @@ public class StatisticsRequestScheduler implements DataTransactionListener { public StatisticsRequestScheduler(){ PendingTransactions = (long) 0; } - + public void addRequestToSchedulerQueue(AbstractStatsTracker statsRequest){ requestQueue.put(statsRequest, null); } - + + public void removeRequestsFromSchedulerQueue(NodeRef node){ + AbstractStatsTracker stats = null; + synchronized(requestQueue){ + Iterator> nodesItr = requestQueue.entrySet().iterator(); + while(nodesItr.hasNext()){ + stats = nodesItr.next().getKey(); + if(stats.getNodeRef().equals(node)){ + nodesItr.remove(); + } + } + } + + } public AbstractStatsTracker getNextRequestFromSchedulerQueue(){ //Remove first element AbstractStatsTracker stats = null; @@ -79,14 +97,11 @@ public class StatisticsRequestScheduler implements DataTransactionListener { private void requestStatistics(){ AbstractStatsTracker stats = this.getNextRequestFromSchedulerQueue(); - if(stats != null) { - stats.request(); - stats.increaseRequestCounter(); - } + sendStatsRequest(stats); } @Override public void onStatusUpdated(DataModificationTransaction transaction, TransactionStatus status) { - + AbstractStatsTracker stats = null; synchronized(PendingTransactions){ switch(status){ @@ -106,12 +121,19 @@ public class StatisticsRequestScheduler implements DataTransactionListener { break; } } + sendStatsRequest(stats); + } + + private void sendStatsRequest(AbstractStatsTracker stats){ if(stats != null){ - stats.request(); - stats.increaseRequestCounter(); + try{ + stats.request(); + stats.increaseRequestCounter(); + }catch(Exception e){ + srsLogger.warn("Statistics request was not sent successfully. Reason : {}",e.getMessage()); + } } } - public void start(){ timer.schedule(task, 0, REQUEST_MONITOR_INTERVAL); }