All Packages  Class Hierarchy  This Package  Previous  Next  Index

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

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

public class Scheduler
extends Object
implements AlarmClockListener, 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

Variable Index

 o ONE_DAY
Number of milliseconds in one day.
 o ONE_HOUR
Number of milliseconds in one hour.
 o ONE_MINUTE
Number of milliseconds in one minute.
 o ONE_SECOND
Number of milliseconds in one second.
 o ONE_WEEK
Number of milliseconds in one week.

Constructor Index

 o Scheduler()
Creates a scheduler object.

Method Index

 o addSchedulerListener(SchedulerListener)
Adds a scheduler listener.
 o getClassVersion()
Returns the version of this class.
 o getDateFromEvent(SchedulerEvent)
Returns a copy of the date of the specified scheduler event.
 o getDateFromIndex(int)
Returns a copy of the date of the scheduler event at the specified index.
 o getListOfEvents()
Returns in an array all the events registered into the vector.
 o getNbRepetitionsFromEvent(SchedulerEvent)
Returns a copy of the remaining number of repetitions of the specified scheduler event.
 o getNbRepetitionsFromIndex(int)
Returns a copy of the remaining number of repetitions of the scheduler event at the specified index.
 o getNotifyPastEvents()
Returns the flag that indicates if the scheduler notifies past events or not.
 o getNumberOfEvents()
Returns the number of events registered into the vector.
 o getPeriodInMillisFromEvent(SchedulerEvent)
Returns a copy of the period in milliseconds of the specified scheduler event.
 o getPeriodInMillisFromIndex(int)
Returns a copy of the period in milliseconds of the scheduler event at the specified index.
 o handleAlarmClock(AlarmClockEvent)
This method is called each time an event has exceeded its time out.
 o isActive()
Tests if the Scheduler is active.
 o isListOfEventsEmpty()
Tests if the list of events is empty.
 o performAddEvent(SchedulerEvent, Date)
Inserts the specified scheduler event into the vector with a null period and a null number of repetitions.
 o performAddEvent(SchedulerEvent, Date, long)
Inserts the specified scheduler event into the vector with a null number of repetitions.
 o performAddEvent(SchedulerEvent, Date, long, long)
Inserts the specified scheduler event into the vector.
 o performRemoveAllEvents()
Removes all the events from the vector.
 o performRemoveEvent(int)
Removes the scheduler event at the specified index from the vector.
 o performRemoveEvent(SchedulerEvent)
Removes the specified scheduler event from the vector.
 o performStart()
Activates the Scheduler service.
 o performStop()
Deactivates the Scheduler service.
 o removeSchedulerListener(SchedulerListener)
Removes a scheduler listener.
 o setNotifyPastEvents(boolean)
Sets the flag that indicates if the scheduler notifies past events or not.

Variables

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

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

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

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

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

Constructors

 o Scheduler
 public Scheduler()
Creates a scheduler object.

Methods

 o handleAlarmClock
 public void handleAlarmClock(AlarmClockEvent event)
This method is called each time an event has exceeded its time out.

Parameters:
event - The alarm clock event.
See Also:
AlarmClockEvent
 o addSchedulerListener
 public void addSchedulerListener(SchedulerListener listener)
Adds a scheduler listener.

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

Parameters:
listener - The scheduler listener to remove.
See Also:
SchedulerListener
 o performAddEvent
 public synchronized void performAddEvent(SchedulerEvent event,
                                          Date date,
                                          long periodInMillis,
                                          long nbRepetitions) throws InstanceAlreadyExistException, InvalidPropertyValueException
Inserts the specified scheduler event into the vector. 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.
Throws: InvalidPropertyValueException
The periodicity has negative values or the date event is before the current date.
See Also:
SchedulerEvent
 o performAddEvent
 public synchronized void performAddEvent(SchedulerEvent event,
                                          Date date,
                                          long periodInMillis) throws InstanceAlreadyExistException, InvalidPropertyValueException
Inserts the specified scheduler event into the vector with 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.
Throws: InvalidPropertyValueException
The periodicity has negative values or the date event is before the current date.
See Also:
SchedulerEvent
 o performAddEvent
 public synchronized void performAddEvent(SchedulerEvent event,
                                          Date date) throws InstanceAlreadyExistException, InvalidPropertyValueException
Inserts the specified scheduler event into the vector with a null period and a null 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.
Throws: InvalidPropertyValueException
The periodicity has negative values or the date event is before the current date.
See Also:
SchedulerEvent
 o performRemoveEvent
 public synchronized 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
 o performRemoveEvent
 public synchronized 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.
 o performRemoveAllEvents
 public synchronized void performRemoveAllEvents()
Removes all the events from the vector.

 o performStart
 public synchronized void performStart()
Activates the Scheduler service.

 o performStop
 public synchronized void performStop()
Deactivates the Scheduler service.

 o isActive
 public boolean isActive()
Tests if the Scheduler is active.

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

 o getDateFromEvent
 public 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
 o getDateFromIndex
 public 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.
 o getPeriodInMillisFromEvent
 public 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
 o getPeriodInMillisFromIndex
 public 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.
 o getNbRepetitionsFromEvent
 public 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
 o getNbRepetitionsFromIndex
 public 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.
 o getNumberOfEvents
 public int getNumberOfEvents()
Returns the number of events registered into the vector.

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

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

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

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


All Packages  Class Hierarchy  This Package  Previous  Next  Index