alshabib

you must call get on futures

Change-Id: I2ed3a9b2250f2a1c6e2e68e35cec50e691702099
1 +package org.onlab.onos.net.flow;
2 +
3 +import java.util.List;
4 +
5 +/**
6 + * Interface capturing the result of a batch operation.
7 + *
8 + */
9 +public interface BatchOperationResult<T> {
10 +
11 + /**
12 + * Returns whether the operation was successful.
13 + * @return true if successful, false otherwise
14 + */
15 + boolean isSuccess();
16 +
17 + /**
18 + * Obtains a list of items which failed.
19 + * @return a list of failures
20 + */
21 + List<T> failedItems();
22 +
23 +}
...@@ -454,7 +454,7 @@ public class FlowRuleManager ...@@ -454,7 +454,7 @@ public class FlowRuleManager
454 454
455 private CompletedBatchOperation finalizeBatchOperation(boolean success, 455 private CompletedBatchOperation finalizeBatchOperation(boolean success,
456 List<FlowEntry> failed) { 456 List<FlowEntry> failed) {
457 - synchronized (overall) { 457 + synchronized (this) {
458 if (!state.compareAndSet(BatchState.STARTED, BatchState.FINISHED)) { 458 if (!state.compareAndSet(BatchState.STARTED, BatchState.FINISHED)) {
459 if (state.get() == BatchState.FINISHED) { 459 if (state.get() == BatchState.FINISHED) {
460 return overall; 460 return overall;
......
...@@ -19,8 +19,11 @@ import java.util.Map; ...@@ -19,8 +19,11 @@ import java.util.Map;
19 import java.util.Objects; 19 import java.util.Objects;
20 import java.util.concurrent.ConcurrentHashMap; 20 import java.util.concurrent.ConcurrentHashMap;
21 import java.util.concurrent.ConcurrentMap; 21 import java.util.concurrent.ConcurrentMap;
22 +import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.ExecutorService; 23 import java.util.concurrent.ExecutorService;
23 import java.util.concurrent.Future; 24 import java.util.concurrent.Future;
25 +import java.util.concurrent.TimeUnit;
26 +import java.util.concurrent.TimeoutException;
24 27
25 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 29 import org.apache.felix.scr.annotations.Component;
...@@ -516,9 +519,15 @@ public class IntentManager ...@@ -516,9 +519,15 @@ public class IntentManager
516 public void run() { 519 public void run() {
517 for (Iterator<Future<CompletedBatchOperation>> i = futures.iterator(); i.hasNext();) { 520 for (Iterator<Future<CompletedBatchOperation>> i = futures.iterator(); i.hasNext();) {
518 Future<CompletedBatchOperation> future = i.next(); 521 Future<CompletedBatchOperation> future = i.next();
519 - if (future.isDone()) { 522 + try {
520 - // TODO: we may want to get the future here 523 + // TODO: we may want to get the future here and go back to the future.
524 + future.get(100, TimeUnit.NANOSECONDS);
525 +
526 +
521 i.remove(); 527 i.remove();
528 +
529 + } catch (TimeoutException | InterruptedException | ExecutionException te) {
530 + log.debug("Intallations of intent {} is still pending", intent);
522 } 531 }
523 } 532 }
524 if (futures.isEmpty()) { 533 if (futures.isEmpty()) {
......
...@@ -430,9 +430,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -430,9 +430,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
430 public CompletedBatchOperation get(long timeout, TimeUnit unit) 430 public CompletedBatchOperation get(long timeout, TimeUnit unit)
431 throws InterruptedException, ExecutionException, 431 throws InterruptedException, ExecutionException,
432 TimeoutException { 432 TimeoutException {
433 - countDownLatch.await(timeout, unit); 433 + if (countDownLatch.await(timeout, unit)) {
434 - this.state = BatchState.FINISHED; 434 + this.state = BatchState.FINISHED;
435 - return new CompletedBatchOperation(ok.get(), offendingFlowMods); 435 + return new CompletedBatchOperation(ok.get(), offendingFlowMods);
436 + }
437 + throw new TimeoutException();
436 } 438 }
437 439
438 private void cleanUp() { 440 private void cleanUp() {
......