atg.service.scheduler
Class Scheduler

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.scheduler.Scheduler
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class Scheduler
extends GenericService

A Scheduler keeps track of ScheduledJobs and executes those jobs according to their Schedules. The Scheduler is run by a single Thread that sleeps until the next job is to be run.

This implementation of Scheduler keeps a list of all of its ScheduledJobs, sorted by next time of occurrence. The Scheduler also keeps a list of "unscheduled" jobs that cannot calculate their next times of occurrence. Every morning at midnight, the Scheduler walks through the "unscheduled" list to see if any jobs can now determine their next occurrence time and therefore be added to the "scheduled" list.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
Scheduler()
          Constructs a blank new Scheduler
 
Method Summary
 int addScheduledJob(ScheduledJob pJob)
          Adds the specified ScheduledJob to the Scheduler.
protected  javax.servlet.Servlet createAdminServlet()
          Creates and returns a new Servlet that will administer this service.
 void doStartService()
          This will start the thread running
 void doStopService()
          This will stop the scheduler thread
 ScheduledJob findScheduledJob(int pJobId)
          Returns the ScheduledJob associated with the given id, or null if there is none.
 int getJobCount()
          Returns the total number of jobs waiting to occur or to be scheduled.
 int getJobOccurrenceCount()
          Returns the number jobs that have occurred.
 long getLastDelayAmount()
           
 long getLastDelayEndTime()
           
 long getLastDelayStartTime()
           
 long getNextTime()
          Returns the time of the next task to be executed, or midnight tomorrow morning, whichever comes first.
 java.lang.String getNextTimeFormatted()
           
 java.lang.String getPerformanceMonitorOpName()
           
 int getScheduledJobCount()
          Returns the number of ScheduledJobs waiting to occur.
 javax.transaction.TransactionManager getTransactionManager()
           
 boolean getTransactionsEnabled()
           
 java.lang.String getTransAttribute()
           
 int getTransAttributeCode()
           
 int getUnscheduledJobCount()
          Returns the number of UnscheduledJobs waiting to occur.
 ScheduledJob[] getUnscheduledJobs()
           
 boolean isPerformanceMonitorEnabled()
           
 int parseTransAttribute(java.lang.String pTransAttribute)
          Returns the transaction attribute code for the given trans attribute string.
 void removeScheduledJob(int pJobId)
          Removes the ScheduledJob with the given id.
 void setLastDelayAmount(long pLastDelayAmount)
           
 void setLastDelayEndTime(long pLastDelayEndTime)
           
 void setLastDelayStartTime(long pLastDelayStartTime)
           
 void setPerformanceMonitorEnabled(boolean pPerformanceMonitorEnabled)
           
 void setPerformanceMonitorOpName(java.lang.String pPerformanceMonitorOpName)
           
 void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)
           
 void setTransactionsEnabled(boolean pTransactionsEnabled)
           
 void setTransAttribute(java.lang.String pTransAttribute)
          The transaction attribute that should be used on every job - must be one of "required", "requiresNew", "supports", "notSupported", "mandatory", "never".
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

Scheduler

public Scheduler()
Constructs a blank new Scheduler

Method Detail

getLastDelayStartTime

public long getLastDelayStartTime()

setLastDelayStartTime

public void setLastDelayStartTime(long pLastDelayStartTime)

getLastDelayEndTime

public long getLastDelayEndTime()

setLastDelayEndTime

public void setLastDelayEndTime(long pLastDelayEndTime)

getLastDelayAmount

public long getLastDelayAmount()

setLastDelayAmount

public void setLastDelayAmount(long pLastDelayAmount)

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()

setTransactionManager

public void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)

getTransactionsEnabled

public boolean getTransactionsEnabled()

setTransactionsEnabled

public void setTransactionsEnabled(boolean pTransactionsEnabled)

getTransAttribute

public java.lang.String getTransAttribute()

setTransAttribute

public void setTransAttribute(java.lang.String pTransAttribute)
The transaction attribute that should be used on every job - must be one of "required", "requiresNew", "supports", "notSupported", "mandatory", "never". Set to "required" by default, which causes it to create a transaction on every job. Setting it to "supports" is the best way to have it not create a transaction on every job - it will still check to make sure that no transactions are "left over" at the end of a job.


getTransAttributeCode

public int getTransAttributeCode()

isPerformanceMonitorEnabled

public boolean isPerformanceMonitorEnabled()

setPerformanceMonitorEnabled

public void setPerformanceMonitorEnabled(boolean pPerformanceMonitorEnabled)

getPerformanceMonitorOpName

public java.lang.String getPerformanceMonitorOpName()

setPerformanceMonitorOpName

public void setPerformanceMonitorOpName(java.lang.String pPerformanceMonitorOpName)

getUnscheduledJobs

public ScheduledJob[] getUnscheduledJobs()

addScheduledJob

public int addScheduledJob(ScheduledJob pJob)
Adds the specified ScheduledJob to the Scheduler. This will generate and return the job id to be used as the key for accessing this job. Valid job ids are always greater than 0.


findScheduledJob

public ScheduledJob findScheduledJob(int pJobId)
Returns the ScheduledJob associated with the given id, or null if there is none.


removeScheduledJob

public void removeScheduledJob(int pJobId)
Removes the ScheduledJob with the given id. Does nothing if the job id does not exist.


getJobOccurrenceCount

public int getJobOccurrenceCount()
Returns the number jobs that have occurred.


getScheduledJobCount

public int getScheduledJobCount()
Returns the number of ScheduledJobs waiting to occur.


getUnscheduledJobCount

public int getUnscheduledJobCount()
Returns the number of UnscheduledJobs waiting to occur.


getJobCount

public int getJobCount()
Returns the total number of jobs waiting to occur or to be scheduled.


getNextTime

public long getNextTime()
Returns the time of the next task to be executed, or midnight tomorrow morning, whichever comes first.


getNextTimeFormatted

public java.lang.String getNextTimeFormatted()

doStartService

public void doStartService()
                    throws ServiceException
This will start the thread running

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

doStopService

public void doStopService()
This will stop the scheduler thread

Overrides:
doStopService in class GenericService

parseTransAttribute

public int parseTransAttribute(java.lang.String pTransAttribute)
                        throws ServiceException
Returns the transaction attribute code for the given trans attribute string. Throws a ServiceException if the trans attribute is unrecognized.

Throws:
ServiceException

createAdminServlet

protected javax.servlet.Servlet createAdminServlet()
Creates and returns a new Servlet that will administer this service. By default, this creates a ServiceAdminServlet, but subclasses may create their own servlets.

Overrides:
createAdminServlet in class GenericService