org.mbari.siam.tests.moos.deployed
Class TestScheduleOwner

java.lang.Object
  extended by org.mbari.siam.tests.moos.deployed.TestScheduleOwner
All Implemented Interfaces:
ScheduleOwner

public class TestScheduleOwner
extends java.lang.Object
implements ScheduleOwner

TestScheduleOwner is a class to demonstrate the use of the Scheduler and related classes: - Scheduler: provides application global view of schedules, supporting operations like showSchedule and getNextScheduledJob - ScheduleTaskImpl: an implementation of ScheduleTask, which encapsulates scheduling timing and control - ScheduleSpecifier: cron-like representation of schedules - Scheduler.ScheduleKey: an inner class of Scheduler, a unique ScheduleOwnerID used in some contexts to resolve ownership of ScheduleTasks (e.g., to differentiate between two ScheduleTasks with the same name, owned by objects of the same class). - ScheduleOwner: an interface that must be fulfilled by things that use schedules To use a schedule, a class must: - implement ScheduleOwner (an interface with 3 methods) - obtain a ScheduleKey object - create one or more ScheduleTasks - register the ScheduleTasks with the Scheduler - start the schedules running (or have them started by something other class) - optionally provide any accessor methods required by the application

Author:
Kent Headley
See Also:
Scheduler, ScheduleTaskImpl, ScheduleSpecifier, ScheduleOwner

Field Summary
protected static org.apache.log4j.Logger _log4j
          Log4j logger
 
Constructor Summary
TestScheduleOwner()
          Empty Constructor
 
Method Summary
 int addSchedule(ScheduleTask schedule, boolean overwrite)
           
 int addSchedule(java.lang.String name, java.lang.String specifier, boolean overwrite)
          Add or replace schedule.
 void badRemoveSchedule(java.lang.String name)
           
 ScheduleTask createTask(java.lang.String name, ScheduleSpecifier schedule, ScheduleOwner parent)
          A factory method to generate ScheduleTasks (Not strictly necessary; can do this on the fly)
 void doScheduledTask(ScheduleTask task)
          Default method to execute
 java.util.Collection getAllSchedules()
          Return schedules
 ScheduleTask getSchedule(java.lang.String name)
          Get a schedule by name
 Scheduler.ScheduleKey getScheduleKey()
          Return schedule key (unique schedule owner ID)
static void main(java.lang.String[] args)
          A demonstration of this class Using schedules is easy, nutritious and fun for the whole family.
 int removeAllSchedules()
          Remove all schedules.
 int removeSchedule(java.lang.String name)
          Remove specified schedule.
 int resumeSchedule(java.lang.String name)
          Resume specified schedule.
 void setKey(Scheduler.ScheduleKey key)
          Set schedule key (unique schedule owner ID)
 void setupSchedules(java.lang.String dfltSchedule, java.lang.String altSchedule)
          Create schedules and register them with the scheduler.
 long sleepingUntil(ScheduleTask task)
          If execution thread of specified task is sleeping, return time at which it will resume; otherwise return 0.
 int suspendSchedule(java.lang.String name)
          Suspend specified schedule.Return integer code defined by Scheduler.
 int syncSchedule(java.lang.String name, long delay)
          "Synchronize" specified schedule.
 void theAlternativeThingToDo(ScheduleTask st)
          Another of the methods this class wants to execute on a schedule
 void theDefaultThingToDo(ScheduleTask st)
          One of the methods this class wants to execute on a schedule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log4j

protected static org.apache.log4j.Logger _log4j
Log4j logger

Constructor Detail

TestScheduleOwner

public TestScheduleOwner()
Empty Constructor

Method Detail

theDefaultThingToDo

public void theDefaultThingToDo(ScheduleTask st)
One of the methods this class wants to execute on a schedule


theAlternativeThingToDo

public void theAlternativeThingToDo(ScheduleTask st)
Another of the methods this class wants to execute on a schedule


createTask

public ScheduleTask createTask(java.lang.String name,
                               ScheduleSpecifier schedule,
                               ScheduleOwner parent)
A factory method to generate ScheduleTasks (Not strictly necessary; can do this on the fly)


setupSchedules

public void setupSchedules(java.lang.String dfltSchedule,
                           java.lang.String altSchedule)
Create schedules and register them with the scheduler.


getSchedule

public ScheduleTask getSchedule(java.lang.String name)
Get a schedule by name


addSchedule

public int addSchedule(ScheduleTask schedule,
                       boolean overwrite)

setKey

public void setKey(Scheduler.ScheduleKey key)
Set schedule key (unique schedule owner ID)


badRemoveSchedule

public void badRemoveSchedule(java.lang.String name)

doScheduledTask

public void doScheduledTask(ScheduleTask task)
Default method to execute

Specified by:
doScheduledTask in interface ScheduleOwner

getAllSchedules

public java.util.Collection getAllSchedules()
Return schedules

Specified by:
getAllSchedules in interface ScheduleOwner

getScheduleKey

public Scheduler.ScheduleKey getScheduleKey()
Return schedule key (unique schedule owner ID)

Specified by:
getScheduleKey in interface ScheduleOwner

addSchedule

public int addSchedule(java.lang.String name,
                       java.lang.String specifier,
                       boolean overwrite)
Add or replace schedule. Return integer code defined by Scheduler.

Specified by:
addSchedule in interface ScheduleOwner

syncSchedule

public int syncSchedule(java.lang.String name,
                        long delay)
"Synchronize" specified schedule. Return integer code defined by Scheduler.

Specified by:
syncSchedule in interface ScheduleOwner

removeAllSchedules

public int removeAllSchedules()
Remove all schedules. Return integer code defined by Scheduler.

Specified by:
removeAllSchedules in interface ScheduleOwner

removeSchedule

public int removeSchedule(java.lang.String name)
Remove specified schedule. Return integer code defined by Scheduler.

Specified by:
removeSchedule in interface ScheduleOwner

suspendSchedule

public int suspendSchedule(java.lang.String name)
Suspend specified schedule.Return integer code defined by Scheduler.

Specified by:
suspendSchedule in interface ScheduleOwner

resumeSchedule

public int resumeSchedule(java.lang.String name)
Resume specified schedule. Return integer code defined by Scheduler.

Specified by:
resumeSchedule in interface ScheduleOwner

sleepingUntil

public long sleepingUntil(ScheduleTask task)
If execution thread of specified task is sleeping, return time at which it will resume; otherwise return 0.

Specified by:
sleepingUntil in interface ScheduleOwner

main

public static void main(java.lang.String[] args)
A demonstration of this class Using schedules is easy, nutritious and fun for the whole family. Schedules...they're really neat!



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.