Class AbstractSchedulerService
- java.lang.Object
-
- org.apache.turbine.services.BaseInitable
-
- org.apache.turbine.services.BaseService
-
- org.apache.turbine.services.TurbineBaseService
-
- org.apache.turbine.services.schedule.AbstractSchedulerService
-
- All Implemented Interfaces:
Initable,ScheduleService,Service
- Direct Known Subclasses:
TorqueSchedulerService,TurbineNonPersistentSchedulerService
public abstract class AbstractSchedulerService extends TurbineBaseService implements ScheduleService
Service for a cron like scheduler.- Version:
- $Id: TorqueSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
- Author:
- Dave Bryson, Quinton McCombs
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractSchedulerService.MainLoopInner class.
-
Field Summary
Fields Modifier and Type Field Description protected booleanenabledCurrent status of the schedulerprotected static org.apache.logging.log4j.LoggerlogLoggingprotected AbstractSchedulerService.MainLoopmainLoopThe main loop for starting jobs.protected JobQueue<JobEntry>scheduleQueueThe queueprotected ThreadthreadThe 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
-
Fields inherited from interface org.apache.turbine.services.Service
SERVICE_NAME
-
-
Constructor Summary
Constructors Constructor Description AbstractSchedulerService()Creates a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddJob(JobEntry je)Add a new job to the queue.protected voidclearThread()Set thread to null to indicate termination.abstract JobEntrygetJob(int oid)Get a specific Job from Storage.ThreadgetThread()Return the thread being used to process commands, or null if there is no such thread.voidinit()Initializes the SchedulerService.booleanisEnabled()Determines if the scheduler service is currently enabled.List<JobEntry>listJobs()List jobs in the queue.protected abstract List<? extends JobEntry>loadJobs()Load all jobs from configuration storageabstract JobEntrynewJob(int sec, int min, int hour, int wd, int day_mo, String task)Factory method for a new Job Schedule a job to run on a certain point of time.
Example 1: Run the DefaultScheduledJob at 8:00am every 15th of the month -
JobEntry je = newJob(0,0,8,-1,15,"DefaultScheduledJob");
Example 2: Run the DefaultScheduledJob at 8:00am every day -
JobEntry je = newJob(0,0,8,-1,-1,"DefaultScheduledJob");
Example 3: Run the DefaultScheduledJob every 2 hours. -
JobEntry je = newJob(0,120,-1,-1,-1,"DefaultScheduledJob");
Example 4: Run the DefaultScheduledJob every 30 seconds. -
JobEntry je = newJob(30,-1,-1,-1,-1,"DefaultScheduledJob");protected JobEntrynextJob()Return the next Job to execute, or null if thread is interrupted.abstract voidremoveJob(JobEntry je)Remove a job from the queue.voidrestart()Start (or restart) a thread to process commands, or wake up an existing thread if one is already running.protected voidsetEnabled(boolean enabled)Sets the enabled status of the schedulervoidshutdown()Shutdowns the service.voidstartScheduler()Starts or restarts the scheduler if not already running.voidstopScheduler()Stops the scheduler if it is currently running.abstract voidupdateJob(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.Initable
getInit, init, setInitableBroker
-
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
-
-
-
-
Field Detail
-
log
protected static final org.apache.logging.log4j.Logger log
Logging
-
scheduleQueue
protected JobQueue<JobEntry> scheduleQueue
The queue
-
enabled
protected boolean enabled
Current status of the scheduler
-
mainLoop
protected AbstractSchedulerService.MainLoop mainLoop
The main loop for starting jobs.
-
-
Constructor Detail
-
AbstractSchedulerService
public AbstractSchedulerService()
Creates a new instance.
-
-
Method Detail
-
init
public void init() throws InitializationException
Initializes the SchedulerService.- Specified by:
initin interfaceInitable- Overrides:
initin classTurbineBaseService- Throws:
InitializationException- Something went wrong in the init stage
-
loadJobs
protected abstract List<? extends JobEntry> loadJobs() throws TurbineException
Load all jobs from configuration storage- Returns:
- the list of pre-configured jobs
- Throws:
TurbineException- if jobs could not be loaded
-
shutdown
public void shutdown()
Shutdowns the service. This methods interrupts the housekeeping thread.- Specified by:
shutdownin interfaceInitable- Overrides:
shutdownin classTurbineBaseService
-
newJob
public abstract JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, String task) throws TurbineException
Description copied from interface:ScheduleServiceFactory method for a new Job Schedule a job to run on a certain point of time.
Example 1: Run the DefaultScheduledJob at 8:00am every 15th of the month -
JobEntry je = newJob(0,0,8,-1,15,"DefaultScheduledJob");
Example 2: Run the DefaultScheduledJob at 8:00am every day -
JobEntry je = newJob(0,0,8,-1,-1,"DefaultScheduledJob");
Example 3: Run the DefaultScheduledJob every 2 hours. -
JobEntry je = newJob(0,120,-1,-1,-1,"DefaultScheduledJob");
Example 4: Run the DefaultScheduledJob every 30 seconds. -
JobEntry je = newJob(30,-1,-1,-1,-1,"DefaultScheduledJob");- Specified by:
newJobin interfaceScheduleService- Parameters:
sec- Value for entry "seconds".min- Value for entry "minutes".hour- Value for entry "hours".wd- Value for entry "week days".day_mo- Value for entry "month days".task- Task to execute.- Returns:
- A JobEntry.
- Throws:
TurbineException- could not create job- See Also:
ScheduleService.newJob(int, int, int, int, int, java.lang.String)
-
getJob
public abstract JobEntry getJob(int oid) throws TurbineException
Get a specific Job from Storage.- Specified by:
getJobin interfaceScheduleService- Parameters:
oid- The int id for the job.- Returns:
- A JobEntry.
- Throws:
TurbineException- job could not be retrieved.
-
addJob
public void addJob(JobEntry je) throws TurbineException
Add a new job to the queue.- Specified by:
addJobin interfaceScheduleService- Parameters:
je- A JobEntry with the job to add.- Throws:
TurbineException- job could not be added
-
removeJob
public abstract void removeJob(JobEntry je) throws TurbineException
Remove a job from the queue.- Specified by:
removeJobin interfaceScheduleService- Parameters:
je- A JobEntry with the job to remove.- Throws:
TurbineException- job could not be removed
-
updateJob
public abstract void updateJob(JobEntry je) throws TurbineException
Add or update a job.- Specified by:
updateJobin interfaceScheduleService- Parameters:
je- A JobEntry with the job to modify- Throws:
TurbineException- job could not be updated
-
listJobs
public List<JobEntry> listJobs()
List jobs in the queue. This is used by the scheduler UI.- Specified by:
listJobsin interfaceScheduleService- Returns:
- A List of jobs.
-
setEnabled
protected void setEnabled(boolean enabled)
Sets the enabled status of the scheduler- Parameters:
enabled- true to enable the scheduler
-
isEnabled
public boolean isEnabled()
Determines if the scheduler service is currently enabled.- Specified by:
isEnabledin interfaceScheduleService- Returns:
- Status of the scheduler service.
-
startScheduler
public void startScheduler()
Starts or restarts the scheduler if not already running.- Specified by:
startSchedulerin interfaceScheduleService
-
stopScheduler
public void stopScheduler()
Stops the scheduler if it is currently running.- Specified by:
stopSchedulerin interfaceScheduleService
-
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
protected 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
protected JobEntry nextJob() throws TurbineException
Return the next Job to execute, or null if thread is interrupted.- Returns:
- A JobEntry.
- Throws:
TurbineException- a generic exception.
-
-