com.sun.jaw.impl.agent.services.scheduler
Class Scheduler

java.lang.Object
  |
  +--com.sun.jaw.impl.agent.services.scheduler.Scheduler

public class Scheduler
extends java.lang.Object
implements AlarmClockListener, java.io.Serializable, ActivatableIf

This class provides a simple implementation of a scheduler service. The scheduler service sends out an alarm at a specified time that wakes up all the listeners registered to receive scheduler events.

Implements a SchedulerListener interface in all objects that are required to receive events of type SchedulerEvent. The SchedulerEvent is a simple implementation of an event used by the scheduler service.

This class uses a vector to store the scheduler events. A method allows users to add/remove as many events as required. Added scheduler events can be made into regularly repeating events. Users can start or stop the scheduler service by invoking the performStart/performStop methods.

Note:

All events before the time when the performAddEvent method is called are ignored irrespective of the notifyPastEvents flag.

See Also:
SchedulerListener, SchedulerEvent, Serialized Form

Field Summary
static long ONE_DAY
          Number of milliseconds in one day.
static long ONE_HOUR
          Number of milliseconds in one hour.
static long ONE_MINUTE
          Number of milliseconds in one minute.
static long ONE_SECOND
          Number of milliseconds in one second.
static long ONE_WEEK
          Number of milliseconds in one week.
 
Constructor Summary
Scheduler()
          Creates a scheduler object.
 
Method Summary
 void addSchedulerListener(SchedulerListener listener)
          Adds a scheduler listener.
static java.lang.String getClassVersion()
          Returns the version of this class.
 java.util.Date getDateFromEvent(SchedulerEvent event)
          Returns a copy of the date of the specified scheduler event.
 java.util.Date getDateFromIndex(int index)
          Returns a copy of the date of the scheduler event at the specified index.
 SchedulerEvent[] getListOfEvents()
          Returns in an array all the events registered into the vector.
 java.lang.Long getNbRepetitionsFromEvent(SchedulerEvent event)
          Returns a copy of the remaining number of repetitions of the specified scheduler event.
 java.lang.Long getNbRepetitionsFromIndex(int index)
          Returns a copy of the remaining number of repetitions of the scheduler event at the specified index.
 boolean getNotifyPastEvents()
          Returns the flag that indicates if the scheduler notifies past events or not.
 int getNumberOfEvents()
          Returns the number of events registered into the vector.
 java.lang.Long getPeriodInMillisFromEvent(SchedulerEvent event)
          Returns a copy of the period in milliseconds of the specified scheduler event.
 java.lang.Long getPeriodInMillisFromIndex(int index)
          Returns a copy of the period in milliseconds of the scheduler event at the specified index.
 boolean isActive()
          Tests if the Scheduler is active.
 boolean isListOfEventsEmpty()
          Tests if the list of events is empty.
 void performAddEvent(SchedulerEvent event, java.util.Date date)
          Inserts the specified scheduler event into the vector with a given date and a null period and number of repetitions.
 void performAddEvent(SchedulerEvent event, java.util.Date date, long periodInMillis)
          Inserts the specified scheduler event into the vector with a given date and period and a null number of repetitions.
 void performAddEvent(SchedulerEvent event, java.util.Date date, long periodInMillis, long nbRepetitions)
          Inserts the specified scheduler event into the vector with a given date, period and number of repetitions.
 void performRemoveAllEvents()
          Removes all the events from the vector.
 void performRemoveEvent(int index)
          Removes the scheduler event at the specified index from the vector.
 void performRemoveEvent(SchedulerEvent event)
          Removes the specified scheduler event from the vector.
 void performStart()
          Activates the Scheduler service.
 void performStop()
          Deactivates the Scheduler service.
 void removeSchedulerListener(SchedulerListener listener)
          Removes a scheduler listener.
 void setNotifyPastEvents(boolean b)
          Sets the flag that indicates if the scheduler notifies past events or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_SECOND

public static final long ONE_SECOND
Number of milliseconds in one second. Useful constant for the performAddEvent method.

ONE_MINUTE

public static final long ONE_MINUTE
Number of milliseconds in one minute. Useful constant for the performAddEvent method.

ONE_HOUR

public static final long ONE_HOUR
Number of milliseconds in one hour. Useful constant for the performAddEvent method.

ONE_DAY

public static final long ONE_DAY
Number of milliseconds in one day. Useful constant for the performAddEvent method.

ONE_WEEK

public static final long ONE_WEEK
Number of milliseconds in one week. Useful constant for the performAddEvent method.
Constructor Detail

Scheduler

public Scheduler()
Creates a scheduler object.
Method Detail

addSchedulerListener

public void addSchedulerListener(SchedulerListener listener)
Adds a scheduler listener.
Parameters:
listener - The scheduler listener to add.
See Also:
SchedulerListener

removeSchedulerListener

public void removeSchedulerListener(SchedulerListener listener)
Removes a scheduler listener.
Parameters:
listener - The scheduler listener to remove.
See Also:
SchedulerListener

performAddEvent

public void performAddEvent(SchedulerEvent event,
                            java.util.Date date,
                            long periodInMillis,
                            long nbRepetitions)
                     throws InstanceAlreadyExistException,
                            InvalidPropertyValueException
Inserts the specified scheduler event into the vector with a given date, period and number of repetitions.

If the scheduler event to be inserted has a date that is before the current date, the method attempts to update the event using the defined period. If the defined period is null then the method generates an exception.

If the scheduler event has a non null period, the date of the event is updated by adding the period until the event date is later than the current date. Then the scheduler event is inserted into the vector.

If the specified number of repetitions is non null, the previous mechanism is employed. The number of times that the period is added is limited to the specified number of repetitions. If the event date remains earlier than the current date, an exception is generated.

A specified scheduler event can be added only once.

Note that once the scheduler event has been added into the vector, its associated date, period and number of repetitions cannot be updated.

Parameters:
event - The scheduler event to be added.
date - The date when the event occurs.
periodInMillis - The period of the scheduler event.
nbRepetitions - The number of repetitions of the scheduler event.
Throws:
InstanceAlreadyExistException - The scheduler event to add is already in the vector.
InvalidPropertyValueException - The periodicity has negative values or the date event is before the current date.
See Also:
SchedulerEvent

performAddEvent

public void performAddEvent(SchedulerEvent event,
                            java.util.Date date,
                            long periodInMillis)
                     throws InstanceAlreadyExistException,
                            InvalidPropertyValueException
Inserts the specified scheduler event into the vector with a given date and period and a null number of repetitions.

The scheduler event will repeat continuously using the scheduler period.

Parameters:
event - The scheduler event to be added.
date - The date when the event occurs.
periodInMillis - The period of the scheduler event.
Throws:
InstanceAlreadyExistException - The scheduler event to add is already in the vector.
InvalidPropertyValueException - The periodicity has negative values or the date event is before the current date.
See Also:
SchedulerEvent

performAddEvent

public void performAddEvent(SchedulerEvent event,
                            java.util.Date date)
                     throws InstanceAlreadyExistException,
                            InvalidPropertyValueException
Inserts the specified scheduler event into the vector with a given date and a null period and number of repetitions.

The scheduler event will be handled once at date date.

Parameters:
event - The scheduler event to be added.
date - The date when the event occurs.
Throws:
InstanceAlreadyExistException - The scheduler event to add is already in the vector.
InvalidPropertyValueException - The periodicity has negative values or the date event is before the current date.
See Also:
SchedulerEvent

performRemoveEvent

public void performRemoveEvent(SchedulerEvent event)
                        throws InstanceNotFoundException
Removes the specified scheduler event from the vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.
Parameters:
event - The scheduler event to be removed.
Throws:
InstanceNotFoundException - The scheduler event to remove is not in the vector.
See Also:
SchedulerEvent

performRemoveEvent

public void performRemoveEvent(int index)
                        throws InstanceNotFoundException
Removes the scheduler event at the specified index from the vector. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously.
Parameters:
index - The index in the vector of the scheduler event to remove.
Throws:
InstanceNotFoundException - The index is invalid.

performRemoveAllEvents

public void performRemoveAllEvents()
Removes all the events from the vector.

performStart

public void performStart()
Activates the Scheduler service.
Specified by:
performStart in interface ActivatableIf

performStop

public void performStop()
Deactivates the Scheduler service.
Specified by:
performStop in interface ActivatableIf

isActive

public boolean isActive()
Tests if the Scheduler is active.
Specified by:
isActive in interface ActivatableIf

getListOfEvents

public SchedulerEvent[] getListOfEvents()
Returns in an array all the events registered into the vector.

getDateFromEvent

public java.util.Date getDateFromEvent(SchedulerEvent event)
Returns a copy of the date of the specified scheduler event. Returns null if the specified scheduler event is not in the vector.
Parameters:
event - The scheduler event.
See Also:
SchedulerEvent

getDateFromIndex

public java.util.Date getDateFromIndex(int index)
Returns a copy of the date of the scheduler event at the specified index. Returns null if the specified index is invalid.
Parameters:
index - The index of the scheduler event.

getPeriodInMillisFromEvent

public java.lang.Long getPeriodInMillisFromEvent(SchedulerEvent event)
Returns a copy of the period in milliseconds of the specified scheduler event. Returns null if the specified scheduler event is not in the vector.
Parameters:
event - The scheduler event.
See Also:
SchedulerEvent

getPeriodInMillisFromIndex

public java.lang.Long getPeriodInMillisFromIndex(int index)
Returns a copy of the period in milliseconds of the scheduler event at the specified index. Returns null if the specified index is invalid.
Parameters:
index - The index of the scheduler event.

getNbRepetitionsFromEvent

public java.lang.Long getNbRepetitionsFromEvent(SchedulerEvent event)
Returns a copy of the remaining number of repetitions of the specified scheduler event. Returns null if the specified scheduler event is not in the vector.
Parameters:
event - The scheduler event.
See Also:
SchedulerEvent

getNbRepetitionsFromIndex

public java.lang.Long getNbRepetitionsFromIndex(int index)
Returns a copy of the remaining number of repetitions of the scheduler event at the specified index. Returns null if the specified index is invalid.
Parameters:
index - The index of the scheduler event.

getNumberOfEvents

public int getNumberOfEvents()
Returns the number of events registered into the vector.

getNotifyPastEvents

public boolean getNotifyPastEvents()
Returns the flag that indicates if the scheduler notifies past events or not.

setNotifyPastEvents

public void setNotifyPastEvents(boolean b)
Sets the flag that indicates if the scheduler notifies past events or not.

getClassVersion

public static java.lang.String getClassVersion()
Returns the version of this class.

isListOfEventsEmpty

public boolean isListOfEventsEmpty()
Tests if the list of events is empty.