org.apache.turbine.services.schedule
Class TurbineSchedulerService

java.lang.Object
  extended byorg.apache.turbine.services.BaseInitable
      extended byorg.apache.turbine.services.BaseService
          extended byorg.apache.turbine.services.TurbineBaseService
              extended byorg.apache.turbine.services.schedule.TurbineSchedulerService
All Implemented Interfaces:
Initable, ScheduleService, Service
Direct Known Subclasses:
TurbineNonPersistentSchedulerService

public class TurbineSchedulerService
extends TurbineBaseService
implements ScheduleService

Service for a cron like scheduler.

Version:
$Id: TurbineSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
Author:
Dave Bryson, Quinton McCombs

Nested Class Summary
protected  class TurbineSchedulerService.MainLoop
          Inner class.
 
Field Summary
protected  TurbineSchedulerService.MainLoop mainLoop
          The main loop for starting jobs.
protected  JobQueue scheduleQueue
          The queue
protected  java.lang.Thread thread
          The thread used to process commands.
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.schedule.ScheduleService
INTIALLY_ACTIVE, LOGGER_NAME, SERVICE_NAME
 
Constructor Summary
TurbineSchedulerService()
          Creates a new instance.
 
Method Summary
 void addJob(JobEntry je)
          Add a new job to the queue.
 JobEntry getJob(int oid)
          Get a specific Job from Storage.
 java.lang.Thread getThread()
          Return the thread being used to process commands, or null if there is no such thread.
 void init()
          Initializes the SchedulerService.
 void init(javax.servlet.ServletConfig config)
          Deprecated. use init() instead.
 boolean isEnabled()
          Determines if the scheduler service is currently enabled.
 java.util.List listJobs()
          List jobs in the queue.
 void removeJob(JobEntry je)
          Remove a job from the queue.
 void restart()
          Start (or restart) a thread to process commands, or wake up an existing thread if one is already running.
protected  void setEnabled(boolean enabled)
          Sets the enabled status of the scheduler
 void shutdown()
          Shutdowns the service.
 void startScheduler()
          Starts or restarts the scheduler if not already running.
 void stopScheduler()
          Stops the scheduler if it is currently running.
 void updateJob(JobEntry je)
          Add or update a job.
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker
 

Field Detail

scheduleQueue

protected JobQueue scheduleQueue
The queue


mainLoop

protected TurbineSchedulerService.MainLoop mainLoop
The main loop for starting jobs.


thread

protected java.lang.Thread thread
The thread used to process commands.

Constructor Detail

TurbineSchedulerService

public TurbineSchedulerService()
Creates a new instance.

Method Detail

init

public void init()
          throws InitializationException
Initializes the SchedulerService.

Specified by:
init in interface Initable
Overrides:
init in class TurbineBaseService
Throws:
InitializationException - Something went wrong in the init stage

init

public void init(javax.servlet.ServletConfig config)
          throws InitializationException
Deprecated. use init() instead.

Called the first time the Service is used.
Load all the jobs from cold storage. Add jobs to the queue (sorted in ascending order by runtime) and start the scheduler thread.

Overrides:
init in class TurbineBaseService
Parameters:
config - A ServletConfig.
Throws:
InitializationException - if initialization of this class was not successful.

shutdown

public void shutdown()
Shutdowns the service. This methods interrupts the housekeeping thread.

Specified by:
shutdown in interface Initable
Overrides:
shutdown in class TurbineBaseService

getJob

public JobEntry getJob(int oid)
                throws TurbineException
Get a specific Job from Storage.

Specified by:
getJob in interface ScheduleService
Parameters:
oid - The int id for the job.
Returns:
A JobEntry.
Throws:
TurbineException - job could not be retreived.

addJob

public void addJob(JobEntry je)
            throws TurbineException
Add a new job to the queue.

Specified by:
addJob in interface ScheduleService
Parameters:
je - A JobEntry with the job to add.
Throws:
TurbineException - job could not be added

removeJob

public void removeJob(JobEntry je)
               throws TurbineException
Remove a job from the queue.

Specified by:
removeJob in interface ScheduleService
Parameters:
je - A JobEntry with the job to remove.
Throws:
TurbineException - job could not be removed

updateJob

public void updateJob(JobEntry je)
               throws TurbineException
Add or update a job.

Specified by:
updateJob in interface ScheduleService
Parameters:
je - A JobEntry with the job to modify
Throws:
TurbineException - job could not be updated

listJobs

public java.util.List listJobs()
List jobs in the queue. This is used by the scheduler UI.

Specified by:
listJobs in interface ScheduleService
Returns:
A List of jobs.

setEnabled

protected void setEnabled(boolean enabled)
Sets the enabled status of the scheduler

Parameters:
enabled -

isEnabled

public boolean isEnabled()
Determines if the scheduler service is currently enabled.

Specified by:
isEnabled in interface ScheduleService
Returns:
Status of the scheduler service.

startScheduler

public void startScheduler()
Starts or restarts the scheduler if not already running.

Specified by:
startScheduler in interface ScheduleService

stopScheduler

public void stopScheduler()
Stops the scheduler if it is currently running.

Specified by:
stopScheduler in interface ScheduleService

getThread

public java.lang.Thread getThread()
Return the thread being used to process commands, or null if there is no such thread. You can use this to invoke any special methods on the thread, for example, to interrupt it.

Returns:
A Thread.

restart

public void restart()
Start (or restart) a thread to process commands, or wake up an existing thread if one is already running. This method can be invoked if the background thread crashed due to an unrecoverable exception in an executed command.



Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.