Interface SchedulingService

All Superinterfaces:
TimeProvider

public interface SchedulingService extends TimeProvider
Interface for a service that allows to add and remove handles (typically storing callbacks) for a certain time which are returned when the evaluate method is invoked and the current time is on or after the handle's registered time. It is the expectation that the setTime method is called with same or ascending values for each subsequent call. Handles with are triggered are automatically removed by implementations.
  • Method Details

    • add

      void add(long afterMSec, ScheduleHandle handle, long scheduleSlot) throws ScheduleServiceException
      Add a callback for after the given milliseconds from the current time. If the same callback (equals) was already added before, the method will not add a new callback or change the existing callback to a new time, but throw an exception.
      Parameters:
      afterMSec - number of millisec to get a callback
      handle - to add
      scheduleSlot - allows ordering of concurrent callbacks
      Throws:
      ScheduleServiceException - thrown if the add operation did not complete
    • remove

      void remove(ScheduleHandle handle, long scheduleSlot) throws ScheduleServiceException
      Remove a handle. If the handle to be removed was not found an exception is thrown.
      Parameters:
      handle - to remove
      scheduleSlot - for which the callback was added
      Throws:
      ScheduleServiceException - thrown if the callback was not located
    • setTime

      void setTime(long timestamp)
      Set the time based upon which the evaluation of events invokes callbacks.
      Parameters:
      timestamp - to set
    • evaluate

      void evaluate(Collection<ScheduleHandle> handles)
      Evaluate the current time and add to the collection any handles scheduled for execution.
      Parameters:
      handles - is a collection of handles populated by the service with any callbacks due for the current time
    • destroy

      void destroy()
      Destroy the service.
    • getTimeHandleCount

      int getTimeHandleCount()
      Returns time handle count.
      Returns:
      count
    • getFurthestTimeHandle

      Long getFurthestTimeHandle()
      Returns furthest in the future handle.
      Returns:
      future handle
    • getScheduleHandleCount

      int getScheduleHandleCount()
      Returns count of handles.
      Returns:
      count
    • isScheduled

      boolean isScheduled(ScheduleHandle handle)
      Returns true if the handle has been scheduled already.
      Parameters:
      handle - to check
      Returns:
      indicator whether the handle is in use