org.objectledge.scheduler
Class AbstractScheduler

java.lang.Object
  extended by org.objectledge.scheduler.AbstractScheduler
All Implemented Interfaces:
org.picocontainer.Startable
Direct Known Subclasses:
DBScheduler, TransientScheduler

public abstract class AbstractScheduler
extends Object
implements org.picocontainer.Startable

Base class for scheduler components.

Author:
Pawel Potempski , Rafal Krzewski

Nested Class Summary
private  class AbstractScheduler.RunnerTask
          The worker task that runs a sheduled job.
private  class AbstractScheduler.SchedulerTask
          The daemon task that performs the timekeeping
 
Field Summary
protected  org.jcontainer.dna.Configuration config
          the configuration.
private  org.picocontainer.MutablePicoContainer container
          the container
static String DATE_FORMAT_DEFAULT
          The default DateFormat pattern used by the UI (yyy-MM-dd HH:mm).
protected  DateFormat format
          The date format to be used for the UI.
protected  Map jobs
          The registered jobs.
protected  org.jcontainer.dna.Logger logger
          The logging facility.
private  SortedMap queue
          The job queue.
private  Map runners
          Runners of a specific job.
private  Map scheduleFactory
          The registered schedule types factories.
protected  ThreadPool threadPool
          The pool service.
 
Constructor Summary
AbstractScheduler(org.picocontainer.MutablePicoContainer container, org.jcontainer.dna.Configuration config, org.jcontainer.dna.Logger logger, ThreadPool threadPool, ScheduleFactory[] scheduleFactories)
          Component contructor.
 
Method Summary
abstract  boolean allowsModifications()
          Returns true if the implemenation allows job manipulation at run time.
abstract  AbstractJobDescriptor createJobDescriptor(String name, Schedule schedule, String jobSpec)
          Creates a new scheduled job.
 Schedule createSchedule(String type, String config)
          Creates a Schedule object.
abstract  void deleteJobDescriptor(AbstractJobDescriptor job)
          Deletes a scheduled job.
 void disable(AbstractJobDescriptor job)
          Disables a scheduled job.
 void enable(AbstractJobDescriptor job)
          Enables a scheduled job.
 DateFormat getDateFormat()
          Returns the DateFormat that should be used by the UI.
 AbstractJobDescriptor getJobDescriptor(String name)
          Returns a configured job with the specified name.
 AbstractJobDescriptor[] getJobDescriptors()
          Returns all currently configured jobs.
(package private)  Job getJobObject(AbstractJobDescriptor job)
          Get job component.
 String[] getScheduleTypes()
          Returns available schedule types.
protected abstract  void loadJobs()
          Loads the jobs from storage / configuration.
(package private)  void run(AbstractJobDescriptor job)
          Runs a specified job within a pool service's worker thread.
(package private)  void schedule(AbstractJobDescriptor job)
          Schedules the next execution of a job.
 void start()
          
 void stop()
          
private  void terminate(AbstractJobDescriptor job)
          Terminates execution of all instances of the job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_FORMAT_DEFAULT

public static final String DATE_FORMAT_DEFAULT
The default DateFormat pattern used by the UI (yyy-MM-dd HH:mm).

See Also:
Constant Field Values

container

private org.picocontainer.MutablePicoContainer container
the container


config

protected org.jcontainer.dna.Configuration config
the configuration.


logger

protected org.jcontainer.dna.Logger logger
The logging facility.


threadPool

protected ThreadPool threadPool
The pool service.


scheduleFactory

private Map scheduleFactory
The registered schedule types factories.


jobs

protected Map jobs
The registered jobs.


queue

private SortedMap queue
The job queue.


runners

private Map runners
Runners of a specific job.


format

protected DateFormat format
The date format to be used for the UI.

Constructor Detail

AbstractScheduler

public AbstractScheduler(org.picocontainer.MutablePicoContainer container,
                         org.jcontainer.dna.Configuration config,
                         org.jcontainer.dna.Logger logger,
                         ThreadPool threadPool,
                         ScheduleFactory[] scheduleFactories)
Component contructor.

Parameters:
container - the container to store loaded classes.
config - the configuration.
logger - the logger.
threadPool - the thread pool component.
scheduleFactories - the list of schedule factories.
Method Detail

start

public void start()

Specified by:
start in interface org.picocontainer.Startable

stop

public void stop()

Specified by:
stop in interface org.picocontainer.Startable

createJobDescriptor

public abstract AbstractJobDescriptor createJobDescriptor(String name,
                                                          Schedule schedule,
                                                          String jobSpec)
                                                   throws JobModificationException
Creates a new scheduled job.

Note that newly created jobs are initialy disabled. You need to call enable(AbstractJobDescriptor)to allow the job's execution.

Non-perisistent implementation may decide to disallow creation of new jobs at run time. This mehtod would throw UnsupportedOperationException in that case.

Parameters:
name - the name of the job.
schedule - the job's schedule.
jobSpec - job class specification, see AbstractJobDescriptor.setJobClassName(String)
Returns:
the scheduled job.
Throws:
JobModificationException - if the job could not be instantiated.

deleteJobDescriptor

public abstract void deleteJobDescriptor(AbstractJobDescriptor job)
                                  throws JobModificationException
Deletes a scheduled job.

Non-persisten implementaion may decide to dissalow this operation.

Parameters:
job - the job.
Throws:
JobModificationException - if the job could not be deleted.

enable

public void enable(AbstractJobDescriptor job)
            throws JobModificationException
Enables a scheduled job.

Parameters:
job - the job.
Throws:
JobModificationException - if the job state could not be saved.

disable

public void disable(AbstractJobDescriptor job)
             throws JobModificationException
Disables a scheduled job.

An attempt will be made to terminate all instances of this job running at the moment. Would this attempt be effective depends on the implementation of execute() and terminate(Thread) methods in the Job class.

Parameters:
job - the job.
Throws:
JobModificationException - if the job state could not be saved.

getJobDescriptors

public AbstractJobDescriptor[] getJobDescriptors()
Returns all currently configured jobs.

Returns:
all currently configured jobs.

getJobDescriptor

public AbstractJobDescriptor getJobDescriptor(String name)
Returns a configured job with the specified name.

Parameters:
name - the job's name.
Returns:
the scheduled job.

getScheduleTypes

public String[] getScheduleTypes()
Returns available schedule types.

Returns:
available schedule types.

createSchedule

public Schedule createSchedule(String type,
                               String config)
                        throws InvalidScheduleException
Creates a Schedule object.

Parameters:
type - the schedule type.
config - the schedule configuration.
Returns:
the schedule.
Throws:
InvalidScheduleException - if schedule factory is not registerd.

allowsModifications

public abstract boolean allowsModifications()
Returns true if the implemenation allows job manipulation at run time.

If this method returns false, the following methods are not supported, and should not be called:

Returns:
true if the implemenation allows job manipulation at run time.

getDateFormat

public DateFormat getDateFormat()
Returns the DateFormat that should be used by the UI.

Returns:
the date format.

loadJobs

protected abstract void loadJobs()
Loads the jobs from storage / configuration.


schedule

void schedule(AbstractJobDescriptor job)
Schedules the next execution of a job.

Parameters:
job - the job.

terminate

private void terminate(AbstractJobDescriptor job)
Terminates execution of all instances of the job.


run

void run(AbstractJobDescriptor job)
Runs a specified job within a pool service's worker thread.

Parameters:
job - the job.

getJobObject

Job getJobObject(AbstractJobDescriptor job)
           throws JobNotFoundException
Get job component.

Parameters:
job - the job description.
Returns:
the job object.
Throws:
JobNotFoundException - if job class not found.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.