Package io.deephaven.io.sched
Interface Scheduler
-
- All Known Implementing Classes:
Scheduler.Null,YASchedulerImpl
public interface SchedulerThis class provides a singleton wrapper for scheduling invocations of multiple Job instances from a single thread. Job are scheduled in accordance with an interest set on a java.nio.Channel, deadline based time scheduling, and/or custom criteria defined by the Jobs' implementation of the ready() method. Jobs are instantiated by the application and made known to the scheduler by one of the install() methods. Once the job is installed, the scheduler will call exactly one of its invoke(), timedOut() or cancelled() methods exactly once. After this, the scheduler forgets about the job completely, unless the application installs it again.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classScheduler.ExecutorAdaptorstatic classScheduler.Null
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancelJob(Job job)Cancel a job, making the scheduler forget it completely..voidclose()Shut down the scheduler, calling close() on the underlying Selector.longcurrentTimeMillis()Return the scheduler's idea of the current time.voidinstallJob(Job job, long deadline)Install a job with only an associated deadline (removing any channel association)voidinstallJob(Job job, long deadline, java.nio.channels.SelectableChannel channel, int interest)Install a job in association with a channel and an interest set.booleanisClosed()Return true if the scheduler is closing or closed.java.util.Set<Job>junitGetAllJobs()Return all jobs known to the scheduler, in whatever state.java.util.ArrayList<java.nio.channels.SelectionKey>junitGetAllKeys()Return the selection keys currently known to the scheduler.java.util.Map<java.nio.channels.SelectableChannel,Job>junitGetChannelsAndJobs()Return a map containing all channels and the jobs to which they are associated.java.util.ArrayList<java.nio.channels.SelectionKey>junitGetReadyKeys()Return the selection keys currently known to the scheduler.java.nio.channels.SelectorjunitGetSelector()Return a reference to the selectorjava.util.ArrayList<Job>junitGetTimeoutQueue()Return the contents of the timeout queue, in deadline orderbooleanjunitTestTimeoutQueueInvariant()Return true if the timeout queue invariant holds.booleanwork(long timeout, io.deephaven.base.Procedure.Nullary handoff)Wait for jobs to become ready, then invoke() them all.
-
-
-
Method Detail
-
currentTimeMillis
long currentTimeMillis()
Return the scheduler's idea of the current time.
-
installJob
void installJob(Job job, long deadline, java.nio.channels.SelectableChannel channel, int interest)
Install a job in association with a channel and an interest set.
-
installJob
void installJob(Job job, long deadline)
Install a job with only an associated deadline (removing any channel association)
-
cancelJob
void cancelJob(Job job)
Cancel a job, making the scheduler forget it completely..
-
work
boolean work(long timeout, io.deephaven.base.Procedure.Nullary handoff)Wait for jobs to become ready, then invoke() them all. This method will form the core of the main loop of a scheduler-driven application. The method first waits until: -- the given timeout expires, -- the earliest job-specific timeout expires, or -- one or more jobs becomes ready If jobs have become ready, then the entire ready set will be invoked. If any job throws an uncaught exception, the job's terminated() method will be called and the job deregistered. This does not abort the invocation of the remaining jobs. The return value is then the number of jobs that were invoked. If no jobs are ready and any job-specific timeouts expire, the associated jobs' timedOut() methods are called. The return value is the negative of the number of expired timeouts. If the time given by the timeout argument expires, then zero is returned. Note that this method is not synchronized. The application must ensure that it is never called concurrently by more than one thread.- Returns:
- true, if some job was dispatched
-
close
void close()
Shut down the scheduler, calling close() on the underlying Selector.
-
isClosed
boolean isClosed()
Return true if the scheduler is closing or closed.
-
junitGetSelector
java.nio.channels.Selector junitGetSelector()
Return a reference to the selector
-
junitGetAllJobs
java.util.Set<Job> junitGetAllJobs()
Return all jobs known to the scheduler, in whatever state.
-
junitGetTimeoutQueue
java.util.ArrayList<Job> junitGetTimeoutQueue()
Return the contents of the timeout queue, in deadline order- Returns:
- the jobs in the timeout queue
-
junitGetAllKeys
java.util.ArrayList<java.nio.channels.SelectionKey> junitGetAllKeys()
Return the selection keys currently known to the scheduler.
-
junitGetReadyKeys
java.util.ArrayList<java.nio.channels.SelectionKey> junitGetReadyKeys()
Return the selection keys currently known to the scheduler.
-
junitGetChannelsAndJobs
java.util.Map<java.nio.channels.SelectableChannel,Job> junitGetChannelsAndJobs()
Return a map containing all channels and the jobs to which they are associated.
-
junitTestTimeoutQueueInvariant
boolean junitTestTimeoutQueueInvariant()
Return true if the timeout queue invariant holds.
-
-