diff options
author | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-03 14:08:10 -0800 |
---|---|---|
committer | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-03 14:08:10 -0800 |
commit | 643ee33289bd2cb9e6afbfb09b4ed72d467ba1c2 (patch) | |
tree | c2c376a44a359544fe3d4c45eb0cc0e2ec4a7080 /framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java | |
parent | 46eeb79b54345bdafb6055b8ee4bad4ce8b01274 (diff) |
This updates ONOS src tree to commit id
03fa5e571cabbd001ddb1598847e1150b11c7333
Change-Id: I13b554026d6f902933e35887d29bd5fdb669c0bd
Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java')
-rw-r--r-- | framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java index 4116cbef..8fb008e8 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java @@ -65,6 +65,14 @@ public class ManuallyAdvancingTimer extends java.util.Timer { /* Data structure for tracking tasks */ private final TaskQueue queue = new TaskQueue(); + /* Whether execution should execute on the executor thread or the calling thread. */ + private final boolean runLocally; + + public ManuallyAdvancingTimer(boolean runLocally) { + this.runLocally = runLocally; + } + + @Override public void schedule(TimerTask task, long delay) { if (!staticsPopulated) { @@ -165,14 +173,16 @@ public class ManuallyAdvancingTimer extends java.util.Timer { /** * Advances the virtual time a certain number of millis triggers execution delays a certain amount to - * allow time for execution. + * allow time for execution. If runLocally is true then all real time delays are ignored. * * @param virtualTimeAdvance the time to be advances in millis of simulated time. * @param realTimeDelay the time to delay in real time to allow for processing. */ public void advanceTimeMillis(long virtualTimeAdvance, int realTimeDelay) { timerKeeper.advanceTimeMillis(virtualTimeAdvance); - delay(realTimeDelay); + if (!runLocally) { + delay(realTimeDelay); + } } /** @@ -238,7 +248,11 @@ public class ManuallyAdvancingTimer extends java.util.Timer { e.printStackTrace(); return false; } - executorService.execute(task); + if (runLocally) { + task.run(); + } else { + executorService.execute(task); + } return true; } else { //Calculate next execution time, using absolute value of period @@ -253,7 +267,11 @@ public class ManuallyAdvancingTimer extends java.util.Timer { } //Schedule next execution queue.insertOrdered(task); - executorService.execute(task); + if (runLocally) { + task.run(); + } else { + executorService.execute(task); + } return true; } } |