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 Executors or ExecutorServices 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 classprivate final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DeltaQueue<DeterministicScheduler.ScheduledTask<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) voidinvokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> TinvokeAny(Collection<? extends Callable<T>> tasks) <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) booleanisIdle()Reports whether scheduler is "idle": has no commands pending immediate execution.booleanbooleanvoidRuns the next command scheduled to be executed immediately.voidRuns 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) voidshutdown()private UnsupportedOperationExceptionFuture<?> <T> Future<T> <T> Future<T> voidRuns 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 longMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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:
schedulein interfaceScheduledExecutorService
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceExecutorService
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
toTicks
-
blockingOperationsNotSupported
-
shutdownNotSupported
-