org.apache.turbine.services.schedule
Class TurbineSchedulerService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.TurbineBaseService
                    |
                    +--org.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,v 1.1.1.1 2001/08/16 05:09:15 jvanzyl Exp $
Author:
Dave Bryson

Inner 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, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.schedule.ScheduleService
SERVICE_NAME
 
Constructor Summary
TurbineSchedulerService()
          Creates a new instance.
 
Method Summary
 void addJob(JobEntry je)
          Add a new job to the queue.
private  void clearThread()
          Set thread to null to indicate termination.
 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(javax.servlet.ServletConfig config)
          Called the first time the Service is used.
Load all the jobs from cold storage.
 java.util.Vector listJobs()
          List jobs in the queue.
private  JobEntry nextJob()
          Return the next Job to execute, or null if thread is interrupted.
 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.
 void shutdown()
          Shutdowns the service.
 void updateJob(JobEntry je)
          Modify a Job.
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, 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, registerNatives, 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, 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(javax.servlet.ServletConfig config)
          throws InitializationException
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.

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 java.lang.Exception
Get a specific Job from Storage.
Specified by:
getJob in interface ScheduleService
Parameters:
oid - The int id for the job.
Returns:
A JobEntry.
Throws:
Exception, - a generic exception.

addJob

public void addJob(JobEntry je)
            throws java.lang.Exception
Add a new job to the queue.
Specified by:
addJob in interface ScheduleService
Parameters:
je - A JobEntry with the job to add.
Throws:
Exception, - a generic exception.

removeJob

public void removeJob(JobEntry je)
               throws java.lang.Exception
Remove a job from the queue.
Specified by:
removeJob in interface ScheduleService
Parameters:
je - A JobEntry with the job to remove.
Throws:
Exception, - a generic exception.

updateJob

public void updateJob(JobEntry je)
               throws java.lang.Exception
Modify a Job.
Specified by:
updateJob in interface ScheduleService
Parameters:
je - A JobEntry with the job to modify
Throws:
Exception, - a generic exception.

listJobs

public java.util.Vector listJobs()
List jobs in the queue. This is used by the scheduler UI.
Specified by:
listJobs in interface ScheduleService
Returns:
A Vector of jobs.

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.

clearThread

private void clearThread()
Set thread to null to indicate termination.

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.

nextJob

private JobEntry nextJob()
                  throws java.lang.Exception
Return the next Job to execute, or null if thread is interrupted.
Returns:
A JobEntry.
Throws:
Exception, - a generic exception.


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