Package org.voltdb.task
Class ScheduledAction
java.lang.Object
org.voltdb.task.ScheduledAction
Class which describes an interval, an action to perform after that interval and a callback which should be invoked
after the action has been performed.
This class also has an optional attachment which can be used to pass state between the initiating class and the callback.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ScheduledActioncallback(long interval, TimeUnit timeUnit, Function<ActionResult, ScheduledAction> callback) static ScheduledActionCreate aScheduledActionwhich indicates that an unrecoverable error has occurred and the scheduler must exit.static ScheduledActionCreate aScheduledActionwhich indicates that the scheduler has reached the end of its life cycle gracefully<T> TRetrieve the optional attachment associated with this scheduled actionlonggetInterval(TimeUnit timeUnit) Object[]getType()static ScheduledActionCreate aScheduledActionfrom aActionwhich is of type stop.static ScheduledActionstatic ScheduledActionprocedureCall(long interval, TimeUnit timeUnit, Function<ActionResult, ScheduledAction> callback, String procedure, Object... procedureParameters) Create aScheduledActionwhich executes a procedure with given parameters afterintervalsetAttachment(Object attachment) Add an arbitrary attachment to this instance so that it can be retrieved from theActionResultsetStatusMessage(String statusMessage) Set the optional status message which will be reported in the statistics for a task and if this is anActionType.ERRORorActionType.EXITaction then it will also be logged.toString()
-
Method Details
-
of
Create aScheduledActionfrom aActionwhich is of type stop.- Parameters:
action- BaseActionto get type and message from- Returns:
- A new
ScheduledActionderived fromaction
-
of
- Parameters:
interval- To wait until performingactionaction- To be performed afterinterval- Returns:
- A new
ScheduledActionfrom combiningintervalandaction
-
error
Create aScheduledActionwhich indicates that an unrecoverable error has occurred and the scheduler must exit.statusMessageis the same status message which is set by callingsetStatusMessage(String)- Parameters:
statusMessage- To log indicating the details of the error. May benull- Returns:
- A new
ActionType.ERRORinstance ofScheduledAction
-
exit
Create aScheduledActionwhich indicates that the scheduler has reached the end of its life cycle gracefullystatusMessageis the same status message which is set by callingsetStatusMessage(String)- Parameters:
statusMessage- To log indicating the details of the error. May benull- Returns:
- A new
ActionType.EXITinstance ofScheduledAction
-
procedureCall
public static ScheduledAction procedureCall(long interval, TimeUnit timeUnit, Function<ActionResult, ScheduledAction> callback, String procedure, Object... procedureParameters) Create aScheduledActionwhich executes a procedure with given parameters afterinterval- Parameters:
interval- Interval after which the procedure is to be executedtimeUnit- {#link TimeUnit} ofintervalcallback- That is invoked afterprocedurecompletes executionprocedure- Name of procedure to executeprocedureParameters- To pass to procedure during execution- Returns:
- A new
ActionType.PROCEDUREinstance ofScheduledAction
-
callback
public static ScheduledAction callback(long interval, TimeUnit timeUnit, Function<ActionResult, ScheduledAction> callback) Create aScheduledActionwhich causes thecallbackto be invoked afterinterval. AActionResultwill be associated with this call however it will have anullprocedureandresultbut anattachmentcan be used.- Parameters:
interval- Interval until thecallbackis invokedtimeUnit-TimeUnitofintervalcallback- That is invoked afterintervalhas passed- Returns:
- A new
ActionType.CALLBACKinstance ofScheduledAction
-
getInterval
- Parameters:
timeUnit- Of the returned interval- Returns:
- The time interval until this action should be performed
-
getType
- Returns:
- The
ActionTypeof this action
-
getStatusMessage
- Returns:
- Optional status message provided with any action
-
setStatusMessage
Set the optional status message which will be reported in the statistics for a task and if this is anActionType.ERRORorActionType.EXITaction then it will also be logged. ForActionType.ERRORorActionType.EXITactions this can be provided as part of the factory method.- Parameters:
statusMessage- To be reported- Returns:
this
-
getProcedure
- Returns:
- Name of procedure to execute. Will be
nullif this is not aActionType.PROCEDURE
-
getProcedureParameters
- Returns:
- The parameters that are to be passed the the procedure returned by
getProcedure()
-
getCallback
- Returns:
- The callback to invoke after the
actionhas been performed
-
setAttachment
Add an arbitrary attachment to this instance so that it can be retrieved from theActionResult- Parameters:
attachment- Object to attach. May benull- Returns:
this
-
getAttachment
public <T> T getAttachment()Retrieve the optional attachment associated with this scheduled action- Type Parameters:
T- Type of attachment- Returns:
- The attachment or
nullof there was no attachment
-
toString
-