net.sourceforge.java.util.jobs
Class JobManager

java.lang.Object
  extended bynet.sourceforge.java.util.jobs.JobManager

public class JobManager
extends Object

Central IJob execution context which is used to add and schedule IJobs for execution. Offers the option to register an IJobListener which is notified whenever the status of an IJob executed in the JobManager context changes.

Note: Use shutdown() to safely terminate all running IJobs.

Author:
Sebastian Machhausen

Field Summary
static long DEFAULT_DELAY
           The default delay in milliseconds of ScheduledJob instances if started with a delay.
private  List jobListener
           The List of registered IJobListener objects
private  List jobs
           The List of managed IJobs
private  Timer jobScheduler
           The Timer used to schedule IJobs
private static JobManager SINGLETON_INSTANCE
           The single unique JobManager instance
 
Constructor Summary
private JobManager()
           Creates a new JobManager instance.
 
Method Summary
 void addJob(IJob job)
           Adds the specified IJob to this JobManager.
 void addJob(IJob job, IProgressMonitor monitor)
           Adds the specified IJob to this JobManager.
 void addJobListener(IJobListener listener)
           Adds the specified IJobListener to this JobManager.
protected  void fireJobDone(IJob job)
           Notifies all registered IJobListener that the specified IJob is done.
protected  void fireJobStarted(IJob job)
           Notifies all registered IJobListener that the specified IJob has been started.
protected  void fireJobStatusChanged(IJob job)
           Notifies all registered IJobListener that the status of the specified IJob changed.
static JobManager getInstance()
           Gets the single unique JobManager instance.
 void removeJobListener(IJobListener listener)
           Removes the specified IJobListener from this JobManager.
 void scheduleJob(IJob job, IProgressMonitor monitor, JobExecutionStatus executionStatus)
           Schedules the specified IJob according to the settings in the specified JobExecutionStatus object.
 void scheduleJob(IJob job, IProgressMonitor monitor, long delay)
           Schedules the specified IJob for one time execution after the specified delay.
 void scheduleJob(IJob job, JobExecutionStatus executionStatus)
           Schedules the specified IJob according to the settings in the specified JobExecutionStatus object.
 void scheduleJob(IJob job, long delay)
           Schedules the specified IJob for one time execution after the specified delay.
 void shutdown()
           Shutdown this JobManager by performing a safe termination of all currently running IJob instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELAY

public static final long DEFAULT_DELAY

The default delay in milliseconds of ScheduledJob instances if started with a delay.

See Also:
Constant Field Values

SINGLETON_INSTANCE

private static JobManager SINGLETON_INSTANCE

The single unique JobManager instance


jobs

private List jobs

The List of managed IJobs


jobListener

private List jobListener

The List of registered IJobListener objects


jobScheduler

private Timer jobScheduler

The Timer used to schedule IJobs

Constructor Detail

JobManager

private JobManager()

Creates a new JobManager instance.

Method Detail

getInstance

public static JobManager getInstance()

Gets the single unique JobManager instance.

Returns:
the single unique JobManager instance

addJob

public void addJob(IJob job)

Adds the specified IJob to this JobManager.

Parameters:
job - the IJob to add

addJob

public void addJob(IJob job,
                   IProgressMonitor monitor)

Adds the specified IJob to this JobManager.

Parameters:
job - the IJob to add
monitor - the IProgressMonitor to use for reporting the progress of the specified IJob

scheduleJob

public void scheduleJob(IJob job,
                        JobExecutionStatus executionStatus)

Schedules the specified IJob according to the settings in the specified JobExecutionStatus object. If the schdeduled next execution time of the specified JobExecutionStatus object as returned by the JobExecutionStatus.getNextExecutionTime() method denotes a Date in the past the job is rescheduled to first start at System.currentTimeMillis() + the interval as returned by the JobExecutionStatus.getPeriod() method. After that it is executed in regular intervals as returned by the JobExecutionStatus.getNextExecutionTime() method.

Parameters:
job - the IJob to schedule
executionStatus - the JobExecutionStatus which holds the execution settings

scheduleJob

public void scheduleJob(IJob job,
                        long delay)

Schedules the specified IJob for one time execution after the specified delay.

Parameters:
job - the IJob to schedule
delay - a delay in milliseconds to wait before to execute the specified IJob

scheduleJob

public void scheduleJob(IJob job,
                        IProgressMonitor monitor,
                        JobExecutionStatus executionStatus)

Schedules the specified IJob according to the settings in the specified JobExecutionStatus object. If the schdeduled next execution time of the specified JobExecutionStatus object as returned by the JobExecutionStatus.getNextExecutionTime() method denotes a Date in the past the job is rescheduled to first start at System.currentTimeMillis() + the interval as returned by the JobExecutionStatus.getPeriod() method. After that it is executed in regular intervals as returned by the JobExecutionStatus.getNextExecutionTime() method.

Parameters:
job - the IJob to schedule
monitor - the IProgressMonitor to use for reporting the progress of the IJob
executionStatus - the JobExecutionStatus which holds the execution settings

scheduleJob

public void scheduleJob(IJob job,
                        IProgressMonitor monitor,
                        long delay)

Schedules the specified IJob for one time execution after the specified delay.

Parameters:
job - the IJob to schedule
monitor - the IProgressMonitor to use for reporting the progress of the IJob
delay - a delay in milliseconds to wait before to execute the specified IJob

shutdown

public void shutdown()

Shutdown this JobManager by performing a safe termination of all currently running IJob instances.


addJobListener

public void addJobListener(IJobListener listener)

Adds the specified IJobListener to this JobManager.

Parameters:
listener - the IJobListener to add

removeJobListener

public void removeJobListener(IJobListener listener)

Removes the specified IJobListener from this JobManager.

Parameters:
listener - the IJobListener to remove

fireJobStarted

protected void fireJobStarted(IJob job)

Notifies all registered IJobListener that the specified IJob has been started.

Parameters:
job - the IJob that has been started

fireJobDone

protected void fireJobDone(IJob job)

Notifies all registered IJobListener that the specified IJob is done.

Parameters:
job - the IJob is done

fireJobStatusChanged

protected void fireJobStatusChanged(IJob job)

Notifies all registered IJobListener that the status of the specified IJob changed.

Parameters:
job - the IJob whose status changed