org.apache.avalon.cornerstone.blocks.scheduler
Class DefaultTimeScheduler

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.cornerstone.blocks.scheduler.DefaultTimeScheduler
All Implemented Interfaces:
Disposable, LogEnabled, MonitorableTimeSchedulerMBean, java.lang.Runnable, Serviceable, Startable, TimeScheduler
Direct Known Subclasses:
MonitorableTimeScheduler

public class DefaultTimeScheduler
extends AbstractLogEnabled
implements TimeScheduler, Serviceable, Startable, Disposable, java.lang.Runnable, MonitorableTimeSchedulerMBean

Default implementation of TimeScheduler service.

Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.avalon.cornerstone.services.scheduler.TimeScheduler
ROLE
 
Constructor Summary
DefaultTimeScheduler()
           
 
Method Summary
 void addTrigger(java.lang.String name, TimeTrigger trigger, Target target)
          Schedule a time based trigger.
 void addTriggerFailureListener(TriggerFailureListener listener)
          Add a trigger failure listener
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
protected  void doRunEntry(TimeScheduledEntry entry)
          Helper method delegated to to run in a separate thread.
 java.util.Collection getEntries()
          Return a collection of the triggerable names.
protected  TimeScheduledEntry getEntry(java.lang.String name)
          Retrieve entry from set.
protected  java.util.Map getEntryMap()
           
protected  TimeScheduledEntry getNextEntry()
          Retrieve next valid entry.
protected  PriorityQueue getPriorityQueue()
           
protected  ThreadManager getThreadManager()
           
protected  java.util.List getTriggerFailureListeners()
           
protected  boolean isRunning()
           
protected  void notifyFailedTriggers(java.lang.Throwable t)
           
 void removeTrigger(java.lang.String name)
          Remove a scheduled trigger by name.
 void removeTriggerFailureListener(TriggerFailureListener listener)
          Remove a trigger failure listener
protected  boolean rescheduleEntry(TimeScheduledEntry timeEntry, boolean clone)
          Reschedule an entry.
 void resetTrigger(java.lang.String name)
          Force a trigger time to be recalculated.
 void run()
          Entry point for thread that monitors entrys and triggers entrys when necessary.
protected  void runEntry(TimeScheduledEntry entry)
          Run entry in a separate thread and reschedule it.
 void service(ServiceManager serviceManager)
          Supply of the service manager to the component.
protected  void setRunning(boolean running)
           
 void start()
          Starts the component.
 void stop()
          Stops the component.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTimeScheduler

public DefaultTimeScheduler()
Method Detail

getThreadManager

protected final ThreadManager getThreadManager()

isRunning

protected final boolean isRunning()

setRunning

protected final void setRunning(boolean running)

getTriggerFailureListeners

protected final java.util.List getTriggerFailureListeners()

getEntryMap

protected final java.util.Map getEntryMap()

getPriorityQueue

protected final PriorityQueue getPriorityQueue()

service

public void service(ServiceManager serviceManager)
             throws ServiceException
Supply of the service manager to the component.

Specified by:
service in interface Serviceable
Parameters:
serviceManager - the service manager
Throws:
ServiceException - if an error occurs

dispose

public void dispose()
Description copied from interface: Disposable
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.

Specified by:
dispose in interface Disposable

start

public void start()
           throws java.lang.Exception
Description copied from interface: Startable
Starts the component.

Specified by:
start in interface Startable
Throws:
java.lang.Exception - if Component can not be started

stop

public void stop()
Description copied from interface: Startable
Stops the component.

Specified by:
stop in interface Startable

run

public void run()
Entry point for thread that monitors entrys and triggers entrys when necessary.

Specified by:
run in interface java.lang.Runnable

addTriggerFailureListener

public void addTriggerFailureListener(TriggerFailureListener listener)
Add a trigger failure listener

Specified by:
addTriggerFailureListener in interface TimeScheduler
Parameters:
listener - The listener

removeTriggerFailureListener

public void removeTriggerFailureListener(TriggerFailureListener listener)
Remove a trigger failure listener

Specified by:
removeTriggerFailureListener in interface TimeScheduler
Parameters:
listener - The listener

addTrigger

public void addTrigger(java.lang.String name,
                       TimeTrigger trigger,
                       Target target)
Schedule a time based trigger. Note that if a TimeTrigger already has same name then it is removed.

Specified by:
addTrigger in interface TimeScheduler
Parameters:
name - the name of the trigger
trigger - the trigger
target - the target

removeTrigger

public void removeTrigger(java.lang.String name)
                   throws java.util.NoSuchElementException
Remove a scheduled trigger by name.

Specified by:
removeTrigger in interface TimeScheduler
Parameters:
name - the name of the trigger
Throws:
java.util.NoSuchElementException - if no trigger exists with that name

resetTrigger

public void resetTrigger(java.lang.String name)
                  throws java.util.NoSuchElementException
Force a trigger time to be recalculated.

Specified by:
resetTrigger in interface TimeScheduler
Parameters:
name - the name of the trigger
Throws:
java.util.NoSuchElementException - if no trigger exists with that name

getEntries

public java.util.Collection getEntries()
Return a collection of the triggerable names.

Specified by:
getEntries in interface MonitorableTimeSchedulerMBean
Returns:
the collection

rescheduleEntry

protected boolean rescheduleEntry(TimeScheduledEntry timeEntry,
                                  boolean clone)
Reschedule an entry. if clone is true then invalidate old version and create a new entry to insert into queue.

Parameters:
timeEntry - the entry
clone - true if new entry is to be created
Returns:
true if added to queue, false if not added

getEntry

protected TimeScheduledEntry getEntry(java.lang.String name)
                               throws java.util.NoSuchElementException
Retrieve entry from set.

Parameters:
name - the name of entry
Returns:
the entry
Throws:
java.util.NoSuchElementException - if no entry is found with that name

runEntry

protected void runEntry(TimeScheduledEntry entry)
Run entry in a separate thread and reschedule it.

Parameters:
entry - the entry to run

doRunEntry

protected void doRunEntry(TimeScheduledEntry entry)
Helper method delegated to to run in a separate thread.

Parameters:
entry - the entry to run

getNextEntry

protected TimeScheduledEntry getNextEntry()
Retrieve next valid entry. It will pop off any invalid entrys until the heap is empty or a valid entry is found.

Returns:
the next valid entry or null if none

notifyFailedTriggers

protected void notifyFailedTriggers(java.lang.Throwable t)


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.