Interface Scheduler

All Known Implementing Classes:
Scheduler.Null, YASchedulerImpl

public interface Scheduler
This 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.
  • Method Details

    • currentTimeMillis

      long currentTimeMillis()
      Return the scheduler's idea of the current time.
    • installJob

      void installJob(Job job, long deadline, 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, Runnable 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

      Selector junitGetSelector()
      Return a reference to the selector
    • junitGetAllJobs

      Set<Job> junitGetAllJobs()
      Return all jobs known to the scheduler, in whatever state.
    • junitGetTimeoutQueue

      ArrayList<Job> junitGetTimeoutQueue()
      Return the contents of the timeout queue, in deadline order
      Returns:
      the jobs in the timeout queue
    • junitGetAllKeys

      ArrayList<SelectionKey> junitGetAllKeys()
      Return the selection keys currently known to the scheduler.
    • junitGetReadyKeys

      ArrayList<SelectionKey> junitGetReadyKeys()
      Return the selection keys currently known to the scheduler.
    • junitGetChannelsAndJobs

      Map<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.