net.esper.schedule
Class SchedulingServiceImpl

java.lang.Object
  extended by net.esper.schedule.SchedulingServiceImpl
All Implemented Interfaces:
SchedulingService

public final class SchedulingServiceImpl
extends Object
implements SchedulingService

Implements the schedule service by simply keeping a sorted set of long millisecond values and a set of handles for each.


Constructor Summary
SchedulingServiceImpl()
          Constructor.
 
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 spec, 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 currentTime)
          Set the time based upon which the evaluation of events invokes callbacks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchedulingServiceImpl

public SchedulingServiceImpl()
Constructor.

Method Detail

allocateBucket

public ScheduleBucket allocateBucket()
Description copied from interface: SchedulingService
Returns a bucket from which slots can be allocated for ordering concurrent callbacks.

Specified by:
allocateBucket in interface SchedulingService
Returns:
bucket

getTime

public long getTime()
Description copied from interface: SchedulingService
Gets the last time known to the scheduling service.

Specified by:
getTime in interface SchedulingService
Returns:
time that has last been set on this service

setTime

public final void setTime(long currentTime)
Description copied from interface: SchedulingService
Set the time based upon which the evaluation of events invokes callbacks.

Specified by:
setTime in interface SchedulingService
Parameters:
currentTime - to set

add

public final void add(long afterMSec,
                      ScheduleHandle handle,
                      ScheduleSlot slot)
               throws ScheduleServiceException
Description copied from interface: SchedulingService
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.

Specified by:
add in interface SchedulingService
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

add

public final void add(ScheduleSpec spec,
                      ScheduleHandle handle,
                      ScheduleSlot slot)
Description copied from interface: SchedulingService
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.

Specified by:
add in interface SchedulingService
Parameters:
spec - holds the crontab-like information defining the next occurance
handle - to add
slot - allows ordering of concurrent callbacks

remove

public final void remove(ScheduleHandle handle,
                         ScheduleSlot slot)
Description copied from interface: SchedulingService
Remove a handle. If the handle to be removed was not found an exception is thrown.

Specified by:
remove in interface SchedulingService
Parameters:
handle - to remove
slot - for which the callback was added

evaluate

public final void evaluate(Collection<ScheduleHandle> handles)
Description copied from interface: SchedulingService
Evaluate the current time and add to the collection any handles scheduled for execution.

Specified by:
evaluate in interface SchedulingService
Parameters:
handles - is a collection of handles populated by the service with any callbacks due for the current time