X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fforwardingrulesmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwardingrulesmanager%2Finternal%2FFlowEntryDistributionOrderFutureTask.java;h=b8c2d1db55067b9fc880ccfa74d352a0a45965a0;hb=8fcb3ad33b7d0dae547c48fd57dcadc1488d91db;hp=1ebc300c75ac80c05a5ae6e8dc8b88366468f1c6;hpb=16e527c3b82c24e646355f55910179f9c5138b08;p=controller.git diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/FlowEntryDistributionOrderFutureTask.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/FlowEntryDistributionOrderFutureTask.java index 1ebc300c75..b8c2d1db55 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/FlowEntryDistributionOrderFutureTask.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/FlowEntryDistributionOrderFutureTask.java @@ -36,6 +36,10 @@ final class FlowEntryDistributionOrderFutureTask implements Future { private CountDownLatch waitingLatch; private Status retStatus; private static final Logger logger = LoggerFactory.getLogger(FlowEntryDistributionOrderFutureTask.class); + // Don't wait forever to program, rather timeout if there are issues, and + // log an error + private long timeout; + private static final Long DEFAULTTIMEOUT = 30000L; /** * @param order @@ -49,15 +53,30 @@ final class FlowEntryDistributionOrderFutureTask implements Future { this.waitingLatch = new CountDownLatch(1); // No return status yet! this.retStatus = new Status(StatusCode.UNDEFINED); + // Set the timeout + String strTimeout = System.getProperty("FlowEntryDistributionOrderFutureTask.timeout", + DEFAULTTIMEOUT.toString()); + try { + timeout = Long.parseLong(strTimeout); + } catch (Exception e) { + timeout = DEFAULTTIMEOUT; + } } @Override public boolean cancel(boolean mayInterruptIfRunning) { + if (this.waitingLatch.getCount() != 0L) { + this.retStatus = new Status(StatusCode.GONE); + this.waitingLatch.countDown(); + logger.trace("Cancelled the workOrder"); + return true; + } return false; } @Override public Status get() throws InterruptedException, ExecutionException { + boolean didFinish = false; logger.trace("Getting status for order {}", this.order); // If i'm done lets return the status as many times as caller wants if (this.waitingLatch.getCount() == 0L) { @@ -67,16 +86,23 @@ final class FlowEntryDistributionOrderFutureTask implements Future { logger.trace("Start waiting for status to come back"); // Wait till someone signal that we are done - this.waitingLatch.await(); + didFinish = this.waitingLatch.await(this.timeout, TimeUnit.MILLISECONDS); - logger.trace("Waiting for the status is over, returning it"); - // Return the known status - return retStatus; + if (didFinish) { + logger.trace("Waiting for the status of order {} is over, returning it", this.order); + // Return the known status + return retStatus; + } else { + logger.error("Timing out, the workStatus for order {} has not come back in time!, it's hashcode is {}", + this.order, this.order.hashCode()); + return new Status(StatusCode.TIMEOUT); + } } @Override public Status get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + boolean didFinish = false; logger.trace("Getting status for order {}", this.order); // If i'm done lets return the status as many times as caller wants if (this.waitingLatch.getCount() == 0L) { @@ -86,11 +112,18 @@ final class FlowEntryDistributionOrderFutureTask implements Future { logger.trace("Start waiting for status to come back"); // Wait till someone signal that we are done - this.waitingLatch.await(timeout, unit); + didFinish = this.waitingLatch.await(timeout, unit); - logger.trace("Waiting for the status is over, returning it"); - // Return the known status, could also be null if didn't return - return retStatus; + if (didFinish) { + logger.trace("Waiting for the status is over, returning it"); + // Return the known status, could also be null if didn't return + return retStatus; + } else { + // No need to bark here as long as this routine could indeed + // timeout + logger.trace("Timing out, the workStatus for order {} has not come back in time!", this.order); + return new Status(StatusCode.TIMEOUT); + } } @Override @@ -123,4 +156,12 @@ final class FlowEntryDistributionOrderFutureTask implements Future { this.waitingLatch.countDown(); logger.trace("Unlocked the Future"); } + + /** + * Getter for the workOrder for which the order is waiting for + * @return the order + */ + public FlowEntryDistributionOrder getOrder() { + return order; + } }