Class ScheduledAction

java.lang.Object
org.voltdb.task.ScheduledAction

public class ScheduledAction extends Object
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 Details

    • of

      public static ScheduledAction of(Action action)
      Create a ScheduledAction from a Action which is of type stop.
      Parameters:
      action - Base Action to get type and message from
      Returns:
      A new ScheduledAction derived from action
    • of

      public static ScheduledAction of(Interval interval, Action action)
      Create a ScheduledAction from a Interval and Action. The action must not be of type stop.
      Parameters:
      interval - To wait until performing action
      action - To be performed after interval
      Returns:
      A new ScheduledAction from combining interval and action
    • error

      public static ScheduledAction error(String statusMessage)
      Create a ScheduledAction which indicates that an unrecoverable error has occurred and the scheduler must exit.

      statusMessage is the same status message which is set by calling setStatusMessage(String)

      Parameters:
      statusMessage - To log indicating the details of the error. May be null
      Returns:
      A new ActionType.ERROR instance of ScheduledAction
    • exit

      public static ScheduledAction exit(String statusMessage)
      Create a ScheduledAction which indicates that the scheduler has reached the end of its life cycle gracefully

      statusMessage is the same status message which is set by calling setStatusMessage(String)

      Parameters:
      statusMessage - To log indicating the details of the error. May be null
      Returns:
      A new ActionType.EXIT instance of ScheduledAction
    • procedureCall

      public static ScheduledAction procedureCall(long interval, TimeUnit timeUnit, Function<ActionResult,ScheduledAction> callback, String procedure, Object... procedureParameters)
      Create a ScheduledAction which executes a procedure with given parameters after interval
      Parameters:
      interval - Interval after which the procedure is to be executed
      timeUnit - {#link TimeUnit} of interval
      callback - That is invoked after procedure completes execution
      procedure - Name of procedure to execute
      procedureParameters - To pass to procedure during execution
      Returns:
      A new ActionType.PROCEDURE instance of ScheduledAction
    • callback

      public static ScheduledAction callback(long interval, TimeUnit timeUnit, Function<ActionResult,ScheduledAction> callback)
      Create a ScheduledAction which causes the callback to be invoked after interval . A ActionResult will be associated with this call however it will have a null procedure and result but an attachment can be used.
      Parameters:
      interval - Interval until the callback is invoked
      timeUnit - TimeUnit of interval
      callback - That is invoked after interval has passed
      Returns:
      A new ActionType.CALLBACK instance of ScheduledAction
    • getInterval

      public long getInterval(TimeUnit timeUnit)
      Parameters:
      timeUnit - Of the returned interval
      Returns:
      The time interval until this action should be performed
    • getType

      public ActionType getType()
      Returns:
      The ActionType of this action
    • getStatusMessage

      public String getStatusMessage()
      Returns:
      Optional status message provided with any action
    • setStatusMessage

      public ScheduledAction setStatusMessage(String statusMessage)
      Set the optional status message which will be reported in the statistics for a task and if this is an ActionType.ERROR or ActionType.EXIT action then it will also be logged. For ActionType.ERROR or ActionType.EXIT actions this can be provided as part of the factory method.
      Parameters:
      statusMessage - To be reported
      Returns:
      this
    • getProcedure

      public String getProcedure()
      Returns:
      Name of procedure to execute. Will be null if this is not a ActionType.PROCEDURE
    • getProcedureParameters

      public Object[] getProcedureParameters()
      Returns:
      The parameters that are to be passed the the procedure returned by getProcedure()
    • getCallback

      public Function<ActionResult,ScheduledAction> getCallback()
      Returns:
      The callback to invoke after the action has been performed
    • setAttachment

      public ScheduledAction setAttachment(Object attachment)
      Add an arbitrary attachment to this instance so that it can be retrieved from the ActionResult
      Parameters:
      attachment - Object to attach. May be null
      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 null of there was no attachment
    • toString

      public String toString()
      Overrides:
      toString in class Object