org.cishell.app.service.scheduler
Interface SchedulerService


public interface SchedulerService

A service for scheduling Algorithms to be run. SchedulerListeners may be registered to be notified of events. Application Developers are encouraged to use this service for scheduling Algorithms to be run. Algorithm developers are encouraged not to use this service as it is not guaranteed to be available like the standard CIShell services are.

Author:
Bruce Herr (bh2@bh2.net)

Method Summary
 void addSchedulerListener(SchedulerListener listener)
          Adds a listener to be notified of events happening in the scheduler
 void clearSchedule()
          Clears all currently scheduled Algorithms to be run.
 Algorithm[] getScheduledAlgorithms()
          Returns an array of Algorithms that the scheduler has scheduled.
 Calendar getScheduledTime(Algorithm algorithm)
          Returns the time in which a scheduled Algorithm is scheduled to be run.
 ServiceReference getServiceReference(Algorithm algorithm)
          Returns an Algorithm's associated ServiceReference if one was provided when the Algorithm was scheduled
 boolean isEmpty()
          Returns if there are any Algorithms scheduled
 boolean isRunning()
          Returns whether the scheduler is running
 void removeSchedulerListener(SchedulerListener listener)
          Removes a SchedulerListener from the group of listeners listening for scheduler events.
 boolean reschedule(Algorithm algorithm, Calendar newTime)
          Reschedules an already scheduled Algorithm to be run at a different time.
 void runNow(Algorithm algorithm, ServiceReference ref)
          Schedules an Algorithm to be run immediately.
 void schedule(Algorithm algorithm, ServiceReference ref)
          Schedules an Algorithm to be run when convenient.
 void schedule(Algorithm algorithm, ServiceReference ref, Calendar time)
          Schedules an Algorithm to be run at a specific time.
 void setRunning(boolean isRunning)
          Pauses or unpauses the running of new Algorithms in the scheduler
 boolean unschedule(Algorithm algorithm)
          Unschedules an already scheduled, but not running Algorithm from the scheduler.
 

Method Detail

runNow

void runNow(Algorithm algorithm,
            ServiceReference ref)
Schedules an Algorithm to be run immediately. If there are simply not enough resources to run it, it will still have to wait until there are enough resources to fulfill the request.

Parameters:
algorithm - The algorithm to be run
ref - A reference to the Algorithm's associated service, may be null

schedule

void schedule(Algorithm algorithm,
              ServiceReference ref)
Schedules an Algorithm to be run when convenient. This schedules an Algorithm to be run now, but gives no urgent priority to it. Most Algorithms will be scheduled in this way.

Parameters:
algorithm - The Algorithm to be scheduled
ref - A reference to the Algorithm's associated service, may be null

schedule

void schedule(Algorithm algorithm,
              ServiceReference ref,
              Calendar time)
Schedules an Algorithm to be run at a specific time. The Algorithm will be run at the given time unless there is simply not enough resources at that time. In which case it would wait until there are enough resources to fulfill the request.

Parameters:
algorithm - The Algorithm to be scheduled
ref - A reference to the Algorithm's associated service, may be null
time - What time this Algorithm should be run

reschedule

boolean reschedule(Algorithm algorithm,
                   Calendar newTime)
Reschedules an already scheduled Algorithm to be run at a different time. If the Algorithm is not scheduled already, then this method will have no effect and will return false.

Parameters:
algorithm - The Algorithm already scheduled
newTime - The revised time in which to run the Algorithm
Returns:
If the Algorithm was successfully rescheduled

unschedule

boolean unschedule(Algorithm algorithm)
Unschedules an already scheduled, but not running Algorithm from the scheduler. Tries to unschedule an Algorithm from the scheduler. If the Algorithm isn't in the scheduler or if the Algorithm is already running then this method returns false.

Parameters:
algorithm - The Algorithm to remove from the scheduler
Returns:
If the Algorithm was successfully unscheduled

addSchedulerListener

void addSchedulerListener(SchedulerListener listener)
Adds a listener to be notified of events happening in the scheduler

Parameters:
listener - The listener to be added

removeSchedulerListener

void removeSchedulerListener(SchedulerListener listener)
Removes a SchedulerListener from the group of listeners listening for scheduler events. This method has no effect if the listener isn't in the group of listeners.

Parameters:
listener - The listener to be removed

isRunning

boolean isRunning()
Returns whether the scheduler is running

Returns:
if the scheduler is running

setRunning

void setRunning(boolean isRunning)
Pauses or unpauses the running of new Algorithms in the scheduler

Parameters:
isRunning - true to pause, false to unpause

getScheduledAlgorithms

Algorithm[] getScheduledAlgorithms()
Returns an array of Algorithms that the scheduler has scheduled. This includes the Algorithms that are currently running and the ones queued to be run. This also just gives a snapshot of the current set of scheduled Algorithms, so it is not guaranteed to be accurate even directly after the method returns.

Returns:
The set of Algorithms currently scheduled in the scheduler

getScheduledTime

Calendar getScheduledTime(Algorithm algorithm)
Returns the time in which a scheduled Algorithm is scheduled to be run. The time may be in the past if the Algorithm is already running or null if the Algorithm is not scheduled.

Parameters:
algorithm - The Algorithm
Returns:
The scheduled time for the Algorithm to run or null if the Algorithm is not scheduled or has completed execution

getServiceReference

ServiceReference getServiceReference(Algorithm algorithm)
Returns an Algorithm's associated ServiceReference if one was provided when the Algorithm was scheduled

Parameters:
algorithm - The Algorithm
Returns:
Its associated ServiceReference

clearSchedule

void clearSchedule()
Clears all currently scheduled Algorithms to be run. If an Algorithm is already running, then it will continue to run until finished.


isEmpty

boolean isEmpty()
Returns if there are any Algorithms scheduled

Returns:
Whether there are any Algorithms scheduled