com.espertech.esper.schedule
Class SchedulingServiceImpl

java.lang.Object
  extended by com.espertech.esper.schedule.SchedulingServiceImpl
All Implemented Interfaces:
SchedulingService, SchedulingServiceSPI, TimeProvider

public final class SchedulingServiceImpl
extends java.lang.Object
implements SchedulingServiceSPI

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

Synchronized since statement creation and event evaluation by multiple (event send) threads can lead to callbacks added/removed asynchronously.


Constructor Summary
SchedulingServiceImpl(TimeSourceService timeSourceService)
          Constructor.
 
Method Summary
 void add(long afterMSec, ScheduleHandle handle, ScheduleSlot slot)
          Add a callback for after the given milliseconds from the current time.
 void apply(ScheduleSet scheduleSet)
          Apply the set of schedules.
 void destroy()
          Destroy the service.
 void evaluate(java.util.Collection<ScheduleHandle> handles)
          Evaluate the current time and add to the collection any handles scheduled for execution.
 java.lang.Long getFurthestTimeHandle()
          Returns furthest in the future handle.
 java.lang.String getFurthestTimeHandleDate()
           
 java.lang.Long getNearestTimeHandle()
           
 java.lang.String getNearestTimeHandleDate()
           
 int getScheduleHandleCount()
          Returns count of handles.
 long getTime()
          Returns the current engine time.
 int getTimeHandleCount()
          Returns time handle count.
 boolean isScheduled(ScheduleHandle handle)
          Returns true if the handle has been scheduled already.
 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.
 ScheduleSet take(java.util.Set<java.lang.String> statementIds)
          Take a statement's schedules out of the currently active set of schedules.
 void visitSchedules(ScheduleVisitor visitor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchedulingServiceImpl

public SchedulingServiceImpl(TimeSourceService timeSourceService)
Constructor.

Parameters:
timeSourceService - time source provider
Method Detail

destroy

public void destroy()
Description copied from interface: SchedulingService
Destroy the service.

Specified by:
destroy in interface SchedulingService

getTime

public long getTime()
Description copied from interface: TimeProvider
Returns the current engine time.

Specified by:
getTime in interface TimeProvider
Returns:
time that has last been set

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

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(java.util.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

take

public ScheduleSet take(java.util.Set<java.lang.String> statementIds)
Description copied from interface: SchedulingServiceSPI
Take a statement's schedules out of the currently active set of schedules.

Specified by:
take in interface SchedulingServiceSPI
Parameters:
statementIds - statements to take out
Returns:
schedules

apply

public void apply(ScheduleSet scheduleSet)
Description copied from interface: SchedulingServiceSPI
Apply the set of schedules.

Specified by:
apply in interface SchedulingServiceSPI
Parameters:
scheduleSet - to apply

getTimeHandleCount

public int getTimeHandleCount()
Description copied from interface: SchedulingService
Returns time handle count.

Specified by:
getTimeHandleCount in interface SchedulingService
Returns:
count

getFurthestTimeHandleDate

public java.lang.String getFurthestTimeHandleDate()

getNearestTimeHandleDate

public java.lang.String getNearestTimeHandleDate()

getFurthestTimeHandle

public java.lang.Long getFurthestTimeHandle()
Description copied from interface: SchedulingService
Returns furthest in the future handle.

Specified by:
getFurthestTimeHandle in interface SchedulingService
Returns:
future handle

getScheduleHandleCount

public int getScheduleHandleCount()
Description copied from interface: SchedulingService
Returns count of handles.

Specified by:
getScheduleHandleCount in interface SchedulingService
Returns:
count

isScheduled

public boolean isScheduled(ScheduleHandle handle)
Description copied from interface: SchedulingService
Returns true if the handle has been scheduled already.

Specified by:
isScheduled in interface SchedulingService
Parameters:
handle - to check
Returns:
indicator whether the handle is in use

getNearestTimeHandle

public java.lang.Long getNearestTimeHandle()
Specified by:
getNearestTimeHandle in interface SchedulingServiceSPI

visitSchedules

public void visitSchedules(ScheduleVisitor visitor)
Specified by:
visitSchedules in interface SchedulingServiceSPI

© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com