adams.flow.standalone
Class Cron

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.flow.core.AbstractActor
              extended by adams.flow.standalone.AbstractStandalone
                  extended by adams.flow.standalone.Cron
All Implemented Interfaces:
AdditionalInformationHandler, CleanUpHandler, Debuggable, DebugOutputHandler, Destroyable, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<AbstractActor>, SizeOfHandler, Stoppable, VariableChangeListener, Actor, ActorHandler, DaemonEvent, ErrorHandler, Event, MutableActorHandler, Serializable, Comparable

public class Cron
extends AbstractStandalone
implements MutableActorHandler, DaemonEvent

Executes an actor according to a pre-defined schedule.
Note: since the actor merely starts the cron scheduler in the background, the actor finishes the execution pretty much immediately. Therefore, the flow needs to be kept alive in order to let the background jobs getting executed. This can be done with a simple WhileLoop actor using the 'adams.flow.condition.bool.True' condition and a nested Start/Sleep actor. You can use the adams.flow.template.EndlessLooptemplate to generate this loop automatically.

NB: Any newly scheduled jobs get dropped if the previous execution is still running.

For more information on the scheduler format see:
http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html

Valid options are:

-D <int> (property: debugLevel)
    The greater the number the more additional info the scheme may output to 
    the console (0 = off).
    default: 0
    minimum: 0
 
-name <java.lang.String> (property: name)
    The name of the actor.
    default: Cron
 
-annotation <adams.core.base.BaseText> (property: annotations)
    The annotations to attach to this actor.
    default: 
 
-skip (property: skip)
    If set to true, transformation is skipped and the input token is just forwarded 
    as it is.
 
-stop-flow-on-error (property: stopFlowOnError)
    If set to true, the flow gets stopped in case this actor encounters an error;
     useful for critical actors.
 
-cron-actor <adams.flow.core.AbstractActor> [-cron-actor ...] (property: cronActors)
    The actor to execute according to the cron schedule.
    default: 
 
-schedule <adams.core.base.CronSchedule> (property: schedule)
    The schedule for execution the cron actor; format 'SECOND MINUTE HOUR DAYOFMONTH 
    MONTH WEEKDAY [YEAR]'.
    default: 0 0 1 * * ?
 
For more information on the schedule format, see CronTrigger Tutorial.

Version:
$Revision: 5867 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Nested Class Summary
static class Cron.CronJob
          Encapsulates a job to run.
 
Field Summary
static String BUSY
          the result if actors are currently being executed.
static String KEY_OWNER
          the key for the owner in the JobExecutionContent.
protected  Sequence m_CronActors
          for actors that get executed.
protected  boolean m_ExecutingCronActors
          whether the cron-actors are currently being executed.
protected  CronSchedule m_Schedule
          the cron schedule.
protected  org.quartz.Scheduler m_Scheduler
          the scheduler.
 
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_FullName, m_Headless, m_Name, m_Parent, m_Root, m_Self, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
 
Constructor Summary
Cron()
           
 
Method Summary
 int active()
          Returns the number of non-skipped actors.
 void add(AbstractActor actor)
          Inserts the actor at the end.
 void add(int index, AbstractActor actor)
          Inserts the actor at the given position.
 String check()
          Performs checks on the "sub-actors".
protected  String checkCronActors(AbstractActor[] actors)
          Checks the cron actors before they are set via the setCronActors method.
 void cleanUp()
          Cleans up after the execution has finished.
 String cronActorsTipText()
          Returns the tip text for this property.
 void defineOptions()
          Adds options to the internal list of options.
protected  String doExecute()
          Executes the flow item.
protected  String executeCronActors()
          Executes the cron actors.
 AbstractActor firstActive()
          Returns the first non-skipped actor.
protected  void forceVariables(Variables value)
          Updates the Variables instance in use.
 AbstractActor get(int index)
          Returns the actor at the given position.
 ActorHandlerInfo getActorHandlerInfo()
          Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.
 AbstractActor[] getCronActors()
          Returns the actors to execute on schedule.
 String getQuickInfo()
          Returns a quick info about the actor, which will be displayed in the GUI.
 CronSchedule getSchedule()
          Returns the name of the actor.
 String globalInfo()
          Returns a string describing the object.
 int indexOf(String actor)
          Returns the index of the actor.
protected  void initialize()
          Initializes the members.
 AbstractActor lastActive()
          Returns the last non-skipped actor.
 AbstractActor remove(int index)
          Removes the actor at the given position and returns the removed object.
 void removeAll()
          Removes all actors.
 String scheduleTipText()
          Returns the tip text for this property.
 void set(int index, AbstractActor actor)
          Sets the actor at the given position.
 void setCronActors(AbstractActor[] value)
          Sets the actors to execute on schedule.
 void setDebugLevel(int value)
          Sets the debugging level (0 = off).
 void setSchedule(CronSchedule value)
          Sets the execution schedule.
 String setUp()
          Initializes the sub-actors for flow execution.
 int size()
          Returns the size of the group.
 void stopExecution()
          Stops the execution.
protected  void stopScheduler()
          Stops the internal cron scheduler, if possible.
protected  void updateParent()
          Updates the parent of all actors in this group.
 void wrapUp()
          Cleans up after the execution has finished.
 
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, compareTo, debug, destroy, equals, execute, findVariables, findVariables, findVariables, forCommandLine, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFullName, getName, getNextSibling, getParent, getPreviousSibling, getRoot, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, postExecute, preExecute, pruneBackup, pruneBackup, reset, restoreState, setAnnotations, setErrorHandler, setHeadless, setName, setParent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debugLevelTipText, finishInit, getDebugLevel, getOptionManager, isDebugOn, newOptionManager, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface adams.flow.core.Actor
compareTo, debug, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFullName, getName, getNextSibling, getParent, getPreviousSibling, getRoot, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setHeadless, setName, setParent, setSkip, setStopFlowOnError, setVariables, sizeOf, stopExecution, variableChanged
 
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
 
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
 

Field Detail

KEY_OWNER

public static final String KEY_OWNER
the key for the owner in the JobExecutionContent.

See Also:
Constant Field Values

BUSY

public static final String BUSY
the result if actors are currently being executed.

See Also:
Constant Field Values

m_CronActors

protected Sequence m_CronActors
for actors that get executed.


m_Schedule

protected CronSchedule m_Schedule
the cron schedule.


m_Scheduler

protected org.quartz.Scheduler m_Scheduler
the scheduler.


m_ExecutingCronActors

protected boolean m_ExecutingCronActors
whether the cron-actors are currently being executed.

Constructor Detail

Cron

public Cron()
Method Detail

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class AbstractOptionHandler
Returns:
a description suitable for displaying in the gui

defineOptions

public void defineOptions()
Adds options to the internal list of options.

Specified by:
defineOptions in interface OptionHandler
Overrides:
defineOptions in class AbstractActor

initialize

protected void initialize()
Initializes the members.

Overrides:
initialize in class AbstractActor

getQuickInfo

public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.

Specified by:
getQuickInfo in interface QuickInfoSupporter
Specified by:
getQuickInfo in interface Actor
Overrides:
getQuickInfo in class AbstractActor
Returns:
null if no info available, otherwise short string

setDebugLevel

public void setDebugLevel(int value)
Sets the debugging level (0 = off).

Specified by:
setDebugLevel in interface Debuggable
Overrides:
setDebugLevel in class AbstractOptionHandler
Parameters:
value - >0 if debugging output should be printed

checkCronActors

protected String checkCronActors(AbstractActor[] actors)
Checks the cron actors before they are set via the setCronActors method. Returns an error message if the actors are not acceptable, null otherwise.

Default implementation always returns null.

Parameters:
actors - the actors to check
Returns:
null if accepted, otherwise error message

updateParent

protected void updateParent()
Updates the parent of all actors in this group.


setCronActors

public void setCronActors(AbstractActor[] value)
Sets the actors to execute on schedule.

Parameters:
value - the actors

getCronActors

public AbstractActor[] getCronActors()
Returns the actors to execute on schedule.

Returns:
the actors

cronActorsTipText

public String cronActorsTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the GUI or for listing the options.

setSchedule

public void setSchedule(CronSchedule value)
Sets the execution schedule.

Parameters:
value - the schedule

getSchedule

public CronSchedule getSchedule()
Returns the name of the actor.

Returns:
the name

scheduleTipText

public String scheduleTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the GUI or for listing the options.

executeCronActors

protected String executeCronActors()
Executes the cron actors.

Returns:
null if execution successful, otherwise error message

size

public int size()
Returns the size of the group.

Specified by:
size in interface ActorHandler
Returns:
always 1

get

public AbstractActor get(int index)
Returns the actor at the given position.

Specified by:
get in interface ActorHandler
Parameters:
index - the position
Returns:
the actor

set

public void set(int index,
                AbstractActor actor)
Sets the actor at the given position.

Specified by:
set in interface ActorHandler
Parameters:
index - the position
actor - the actor to set at this position

indexOf

public int indexOf(String actor)
Returns the index of the actor.

Specified by:
indexOf in interface ActorHandler
Parameters:
actor - the name of the actor to look for
Returns:
the index of -1 if not found

add

public void add(AbstractActor actor)
Inserts the actor at the end.

Specified by:
add in interface MutableActorHandler
Parameters:
actor - the actor to insert

add

public void add(int index,
                AbstractActor actor)
Inserts the actor at the given position.

Specified by:
add in interface MutableActorHandler
Parameters:
index - the position
actor - the actor to insert

remove

public AbstractActor remove(int index)
Removes the actor at the given position and returns the removed object.

Specified by:
remove in interface MutableActorHandler
Parameters:
index - the position
Returns:
the removed actor

removeAll

public void removeAll()
Removes all actors.

Specified by:
removeAll in interface MutableActorHandler

getActorHandlerInfo

public ActorHandlerInfo getActorHandlerInfo()
Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.

Specified by:
getActorHandlerInfo in interface ActorHandler
Returns:
the info

active

public int active()
Returns the number of non-skipped actors.

Returns:
the 'active' actors

firstActive

public AbstractActor firstActive()
Returns the first non-skipped actor.

Specified by:
firstActive in interface ActorHandler
Returns:
the first 'active' actor, null if none available

lastActive

public AbstractActor lastActive()
Returns the last non-skipped actor.

Specified by:
lastActive in interface ActorHandler
Returns:
the last 'active' actor, null if none available

check

public String check()
Performs checks on the "sub-actors". Default implementation does nothing.

Specified by:
check in interface ActorHandler
Returns:
null

forceVariables

protected void forceVariables(Variables value)
Updates the Variables instance in use.

Use with caution!

Overrides:
forceVariables in class AbstractActor
Parameters:
value - the instance to use

setUp

public String setUp()
Initializes the sub-actors for flow execution.

Specified by:
setUp in interface Actor
Overrides:
setUp in class AbstractActor
Returns:
null if everything is fine, otherwise error message

doExecute

protected String doExecute()
Executes the flow item.

Specified by:
doExecute in class AbstractActor
Returns:
null if everything is fine, otherwise error message

stopScheduler

protected void stopScheduler()
Stops the internal cron scheduler, if possible.


stopExecution

public void stopExecution()
Stops the execution.

Specified by:
stopExecution in interface Stoppable
Specified by:
stopExecution in interface Actor
Overrides:
stopExecution in class AbstractActor

wrapUp

public void wrapUp()
Cleans up after the execution has finished. Graphical output is left untouched.

Specified by:
wrapUp in interface Actor
Overrides:
wrapUp in class AbstractActor

cleanUp

public void cleanUp()
Cleans up after the execution has finished. Also removes graphical components.

Specified by:
cleanUp in interface CleanUpHandler
Specified by:
cleanUp in interface Actor
Overrides:
cleanUp in class AbstractActor


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.