net.esper.schedule
Interface SchedulingService

All Known Implementing Classes:
SchedulingServiceImpl

public interface SchedulingService

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 Summary
 void add(long afterMSec, ScheduleHandle handle, ScheduleSlot slot)
          Add a callback for after the given milliseconds from the current time.
 void add(ScheduleSpec scheduleSpec, ScheduleHandle handle, ScheduleSlot slot)
          Add a callback for a time specified by the schedule specification passed in based on the current time.
 ScheduleBucket allocateBucket()
          Returns a bucket from which slots can be allocated for ordering concurrent callbacks.
 void evaluate(Collection<ScheduleHandle> handles)
          Evaluate the current time and add to the collection any handles scheduled for execution.
 long getTime()
          Gets the last time known to the scheduling service.
 void remove(ScheduleHandle handle, ScheduleSlot slot)
          Remove a handle.
 void setTime(long timestamp)
          Set the time based upon which the evaluation of events invokes callbacks.
 

Method Detail

add

void add(long afterMSec,
         ScheduleHandle handle,
         ScheduleSlot slot)
         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
slot - allows ordering of concurrent callbacks
Throws:
ScheduleServiceException - thrown if the add operation did not complete
ScheduleHandleExistsException - to indicate the handle already existed

add

void add(ScheduleSpec scheduleSpec,
         ScheduleHandle handle,
         ScheduleSlot slot)
         throws ScheduleServiceException
Add a callback for a time specified by the schedule specification passed in based on 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:
scheduleSpec - holds the crontab-like information defining the next occurance
handle - to add
slot - allows ordering of concurrent callbacks
Throws:
ScheduleServiceException - thrown if the add operation did not complete

remove

void remove(ScheduleHandle handle,
            ScheduleSlot slot)
            throws ScheduleServiceException
Remove a handle. If the handle to be removed was not found an exception is thrown.

Parameters:
handle - to remove
slot - for which the callback was added
Throws:
ScheduleServiceException - thrown if the callback was not located

getTime

long getTime()
Gets the last time known to the scheduling service.

Returns:
time that has last been set on this service

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

allocateBucket

ScheduleBucket allocateBucket()
Returns a bucket from which slots can be allocated for ordering concurrent callbacks.

Returns:
bucket