/** * Constructs a new {@link TestableScheduler} scheduler. * * @param defaultPriority Default priority for tasks which are submitted without any specified priority * @param maxWaitForLowPriorityInMs time low priority tasks to wait if there are high priority tasks ready to run */ public TestableScheduler(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs) { super(defaultPriority); scheduler = new InternalScheduler(defaultPriority, maxWaitForLowPriorityInMs); nowInMillis = Clock.lastKnownTimeMillis(); }
/** * Removes any tasks waiting to be run. Will not interrupt any tasks currently running if * {@link #tick(ExceptionHandler)} is being called. But will avoid additional tasks from being * run on the current {@link #tick(ExceptionHandler)} call. * <p> * If tasks are added concurrently during this invocation they may or may not be removed. * * @return List of runnables which were waiting in the task queue to be executed (and were now removed) */ public List<Runnable> clearTasks() { return scheduler.clearTasks(); }
@Override protected OneTimeTaskWrapper doSchedule(Runnable task, long delayInMillis, TaskPriority priority) { return scheduler.doSchedule(task, delayInMillis, priority); }
/** * Checks how long till the next task will be ready to execute. If there are no tasks in this * scheduler currently then {@link Long#MAX_VALUE} will be returned. If there is a task ready * to execute this will return a value less than or equal to zero. If the task is past its * desired point of execution the result will be a negative amount of milliseconds past that * point in time. * <p> * Generally this is called from the same thread that would invoke * {@link #tick(ExceptionHandler)} (but does not have to be). Since this does not block or lock * if being invoked in parallel with {@link #tick(ExceptionHandler)}, the results may be no * longer accurate by the time this invocation has returned. * <p> * This can be useful if you want to know how long you can block on something, ASSUMING you can * detect that something has been added to the scheduler, and interrupt that blocking in order * to handle tasks. * * @return Milliseconds till the next task is ready to run */ public long getDelayTillNextTask() { return scheduler.getDelayTillNextTask(); }
/** * Checks how long till the next task will be ready to execute. If there are no tasks in this * scheduler currently then {@link Long#MAX_VALUE} will be returned. If there is a task ready * to execute this will return a value less than or equal to zero. If the task is past its * desired point of execution the result will be a negative amount of milliseconds past that * point in time. * <p> * Generally this is called from the same thread that would invoke * {@link #tick(ExceptionHandler)} (but does not have to be). Since this does not block or lock * if being invoked in parallel with {@link #tick(ExceptionHandler)}, the results may be no * longer accurate by the time this invocation has returned. * <p> * This can be useful if you want to know how long you can block on something, ASSUMING you can * detect that something has been added to the scheduler, and interrupt that blocking in order * to handle tasks. * * @return Milliseconds till the next task is ready to run */ public long getDelayTillNextTask() { return scheduler.getDelayTillNextTask(); }
/** * Checks if there are tasks ready to be run on the scheduler. If * {@link #tick(ExceptionHandler)} is not currently being called, this call indicates if the * next {@link #tick(ExceptionHandler)} will have at least one task to run. If * {@link #tick(ExceptionHandler)} is currently being invoked, this call will do a best attempt * to indicate if there is at least one more task to run (not including the task which may * currently be running). It's a best attempt as it will try not to block the thread invoking * {@link #tick(ExceptionHandler)} to prevent it from accepting additional work. * * @return {@code true} if there are task waiting to run */ public boolean hasTaskReadyToRun() { return scheduler.hasTaskReadyToRun(); }
@Override public boolean isShutdown() { return scheduler.isShutdown(); }
@Override public boolean isShutdown() { return scheduler.isShutdown(); }
@Override public int getActiveTaskCount() { return scheduler.getActiveTaskCount(); }
/** * Checks if there are tasks ready to be run on the scheduler. If * {@link #tick(ExceptionHandler)} is not currently being called, this call indicates if the * next {@link #tick(ExceptionHandler)} will have at least one task to run. If * {@link #tick(ExceptionHandler)} is currently being invoked, this call will do a best attempt * to indicate if there is at least one more task to run (not including the task which may * currently be running). It's a best attempt as it will try not to block the thread invoking * {@link #tick(ExceptionHandler)} to prevent it from accepting additional work. * * @return {@code true} if there are task waiting to run */ public boolean hasTaskReadyToRun() { return scheduler.hasTaskReadyToRun(); }
@Override protected OneTimeTaskWrapper doSchedule(Runnable task, long delayInMillis, TaskPriority priority) { return scheduler.doSchedule(task, delayInMillis, priority); }
@Override public int getActiveTaskCount() { return scheduler.getActiveTaskCount(); }
@Override public void scheduleAtFixedRate(Runnable task, long initialDelay, long period, TaskPriority priority) { scheduler.scheduleAtFixedRate(task, initialDelay, period, priority); }
@Override public void scheduleWithFixedDelay(Runnable task, long initialDelay, long recurringDelay, TaskPriority priority) { scheduler.scheduleWithFixedDelay(task, initialDelay, recurringDelay, priority); }
@Override protected QueueManager getQueueManager() { return scheduler.getQueueManager(); }
@Override protected QueueManager getQueueManager() { return scheduler.getQueueManager(); }
/** * Removes any tasks waiting to be run. Will not interrupt any tasks currently running if * {@link #tick(ExceptionHandler)} is being called. But will avoid additional tasks from being * run on the current {@link #tick(ExceptionHandler)} call. * <p> * If tasks are added concurrently during this invocation they may or may not be removed. * * @return List of runnables which were waiting in the task queue to be executed (and were now removed) */ public List<Runnable> clearTasks() { return scheduler.clearTasks(); }
@Override public void scheduleWithFixedDelay(Runnable task, long initialDelay, long recurringDelay, TaskPriority priority) { scheduler.scheduleWithFixedDelay(task, initialDelay, recurringDelay, priority); }
@Override public void scheduleAtFixedRate(Runnable task, long initialDelay, long period, TaskPriority priority) { scheduler.scheduleAtFixedRate(task, initialDelay, period, priority); }
/** * Constructs a new {@link TestableScheduler} scheduler. * * @param defaultPriority Default priority for tasks which are submitted without any specified priority * @param maxWaitForLowPriorityInMs time low priority tasks to wait if there are high priority tasks ready to run */ public TestableScheduler(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs) { super(defaultPriority); scheduler = new InternalScheduler(defaultPriority, maxWaitForLowPriorityInMs); nowInMillis = Clock.lastKnownTimeMillis(); }