Package org.jmock.lib.concurrent
Class DeterministicScheduler
java.lang.Object
org.jmock.lib.concurrent.DeterministicScheduler
- All Implemented Interfaces:
AutoCloseable
,Executor
,ExecutorService
,ScheduledExecutorService
A
ScheduledExecutorService
that executes commands on the thread that calls
runNextPendingCommand
, runUntilIdle
or
tick
. Objects of this class can also be used
as Executor
s or ExecutorService
s if you just want to control background execution
and don't need to schedule commands, but it may be simpler to use a DeterministicExecutor
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
private final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DeltaQueue
<DeterministicScheduler.ScheduledTask<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
awaitTermination
(long timeout, TimeUnit unit) void
invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) boolean
isIdle()
Reports whether scheduler is "idle": has no commands pending immediate execution.boolean
boolean
void
Runs the next command scheduled to be executed immediately.void
Runs all commands scheduled to be executed immediately but does not tick time forward.<V> ScheduledFuture
<V> scheduleAtFixedRate
(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay
(Runnable command, long initialDelay, long delay, TimeUnit unit) void
shutdown()
private UnsupportedOperationException
Future
<?> <T> Future
<T> <T> Future
<T> void
Runs time forwards by a given duration, executing any commands scheduled for execution during that time period, and any background tasks spawned by the scheduled tasks.private long
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.concurrent.ExecutorService
close
-
Field Details
-
deltaQueue
-
-
Constructor Details
-
DeterministicScheduler
public DeterministicScheduler()
-
-
Method Details
-
tick
Runs time forwards by a given duration, executing any commands scheduled for execution during that time period, and any background tasks spawned by the scheduled tasks. Therefore, when a call to tick returns, the executor will be idle.- Parameters:
duration
-timeUnit
-
-
runUntilIdle
public void runUntilIdle()Runs all commands scheduled to be executed immediately but does not tick time forward. -
runNextPendingCommand
public void runNextPendingCommand()Runs the next command scheduled to be executed immediately. -
isIdle
public boolean isIdle()Reports whether scheduler is "idle": has no commands pending immediate execution.- Returns:
- true if there are no commands pending immediate execution, false if there are commands pending immediate execution.
-
execute
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminated
in interfaceExecutorService
-
shutdown
public void shutdown()- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
toTicks
-
blockingOperationsNotSupported
-
shutdownNotSupported
-