org.apache.jetspeed.scheduler
Class AbstractScheduler

java.lang.Object
  extended by org.apache.jetspeed.scheduler.AbstractScheduler
All Implemented Interfaces:
Scheduler
Direct Known Subclasses:
MemoryBasedScheduler

public abstract class AbstractScheduler
extends Object
implements Scheduler

Service for a cron like scheduler.

Version:
$Id: AbstractScheduler.java 516448 2007-03-09 16:25:47Z ate $
Author:
Dave Bryson

Nested Class Summary
protected  class AbstractScheduler.MainLoop
          Inner class.
 
Field Summary
private static org.apache.commons.logging.Log log
           
protected  AbstractScheduler.MainLoop mainLoop
          The main loop for starting jobs.
protected  JobQueue scheduleQueue
          The queue.
protected  Thread thread
          The thread used to process commands.
 
Fields inherited from interface org.apache.jetspeed.scheduler.Scheduler
SERVICE_NAME
 
Constructor Summary
AbstractScheduler()
          Creates a new instance.
 
Method Summary
abstract  void addJob(JobEntry je)
          Add a new job to the queue.
private  void clearThread()
          Set thread to null to indicate termination.
abstract  JobEntry getJob(int oid)
          Get a specific Job from Storage.
 Thread getThread()
          Return the thread being used to process commands, or null if there is no such thread.
 List listJobs()
          List jobs in the queue.
private  JobEntry nextJob()
          Return the next Job to execute, or null if thread is interrupted.
abstract  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 start()
           
 void stop()
           
abstract  void updateJob(JobEntry je)
          Modify a Job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

scheduleQueue

protected JobQueue scheduleQueue
The queue.


mainLoop

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


thread

protected Thread thread
The thread used to process commands.

Constructor Detail

AbstractScheduler

public AbstractScheduler()
Creates a new instance.

Method Detail

start

public void start()

stop

public void stop()

getJob

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

Specified by:
getJob in interface Scheduler
Parameters:
oid - The int id for the job.
Returns:
A JobEntry.
Throws:
Exception, - a generic exception.
Exception

addJob

public abstract void addJob(JobEntry je)
                     throws Exception
Add a new job to the queue. Before adding a job, calculate the runtime to make sure the entry will be placed at the right order in the queue.

Specified by:
addJob in interface Scheduler
Parameters:
je - A JobEntry with the job to add.
Throws:
Exception, - a generic exception.
Exception

removeJob

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

Specified by:
removeJob in interface Scheduler
Parameters:
je - A JobEntry with the job to remove.
Throws:
Exception, - a generic exception.
Exception

updateJob

public abstract void updateJob(JobEntry je)
                        throws Exception
Modify a Job.

Specified by:
updateJob in interface Scheduler
Parameters:
je - A JobEntry with the job to modify
Throws:
Exception, - a generic exception.
Exception

listJobs

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

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

getThread

public 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 Exception
Return the next Job to execute, or null if thread is interrupted.

Returns:
A JobEntry.
Throws:
Exception, - a generic exception.
Exception


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.