Class ContinuationContext

java.lang.Object
rife.continuations.ContinuationContext
All Implemented Interfaces:
Cloneable

public class ContinuationContext extends Object implements Cloneable
Contains all contextual data of one particular continuation.

It also provides some static retrieval methods to be able to access active continuations.

Active continuations are managed in a ContinuationManager so that they can be easily retrieved.

Since:
1.0
See Also:
  • Method Details

    • createOrResetContext

      public static ContinuationContext createOrResetContext(Object executingInstance)
      [PRIVATE AND UNSUPPORTED] Creates a new continuation context or resets its expiration time.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Returns:
      a new ContinuationContext, or the active one with its expiration time being reset
      Since:
      1.0
    • clearActiveContext

      public static void clearActiveContext()
      Clears the active currently continuation context for the executing thread.
      Since:
      1.0
    • getActiveContextId

      public static String getActiveContextId()
      Retrieves the identifier of the currently active continuation for the current thread.
      Returns:
      the identifier of the currently active continuation as a unique string; or

      null if no continuation is currently active

      Since:
      1.0
      See Also:
    • getActiveContext

      public static ContinuationContext getActiveContext()
      Retrieves the currently active continuation for the executing thread.
      Returns:
      the currently active continuation; or

      null if no continuation is currently active

      Since:
      1.0
      See Also:
    • setActiveContext

      public static void setActiveContext(ContinuationContext context)
      Replaces the active continuation context for the executing thread.
      Parameters:
      context - the new ContinuationContext that will be active; or null if no continuation context should be active
      Since:
      1.0
      See Also:
    • getLastContext

      public static ContinuationContext getLastContext()
      Retrieves the last active continuation for the executing thread.
      Returns:
      the last active continuation; or

      null if no continuation was active

      Since:
      1.0
    • getManager

      public ContinuationManager getManager()
      Retrieves the manager of this ContinuationContext.
      Returns:
      this continuation's manager instance
      Since:
      1.0
    • registerContext

      public void registerContext()
      Registers this continuation in its manager, so that it can be retrieved later.
      Since:
      1.0
    • deactivate

      public void deactivate()
      Makes sure that this ContinuationContext is not the active one.
      Since:
      1.0
    • remove

      public void remove()
      Removes this ContinuationContext instance from its ContinuationManager.
      Since:
      1.0
    • removeContextTree

      public void removeContextTree()
      Removes the entire continuation tree that this ContinuationContext instance belongs to from its ContinuationManager.
      Since:
      1.0
    • getParentContextId

      public String getParentContextId()
      Retrieves the unique identifier of the parent continuation of this ContinuationContext instance.
      Returns:
      the parent's identifier as a unique string; or

      null if this ContinuationContext has no parent

      Since:
      1.0
      See Also:
    • getParentContext

      public ContinuationContext getParentContext()
      Retrieves the parent ContinuationContext of this ContinuationContext instance.
      Returns:
      the parent ContinuationContext; or

      null if this ContinuationContext has no parent

      Since:
      1.0
      See Also:
    • getCallAnswer

      public Object getCallAnswer()
      Retrieves the answer that the call continuation stored in this context.
      Returns:
      the call continuation's answer; or

      null if no answer was provided or the corresponding continuation wasn't a call continuation

      Since:
      1.0
    • setPaused

      public void setPaused(boolean paused)
      [PRIVATE AND UNSUPPORTED] Sets whether the continuation if paused.

      This method is used by the internals that provide continuations support, it's not intended for general use.

      Parameters:
      paused - true if the continuation is paused; or

      false otherwise

      Since:
      1.0
      See Also:
    • isPaused

      public boolean isPaused()
      Indicates whether this continuation is actually paused and can be resumed.
      Returns:
      true if the continuation is paused; or

      false otherwise

      Since:
      1.0
    • setLabel

      public void setLabel(int label)
      [PRIVATE AND UNSUPPORTED] Set the number of the bytecode label where the continuation has to resume execution from.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Parameters:
      label - the number of the resumed bytecode label
      Since:
      1.0
    • clearLabel

      public void clearLabel()
      [PRIVATE AND UNSUPPORTED] Set the number of the bytecode label where the continuation has to resume execution from.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Since:
      1.0
    • getLabel

      public int getLabel()
      [PRIVATE AND UNSUPPORTED] Retrieves the number of the bytecode label where the continuation has to resume execution from.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Returns:
      the number of the resumed bytecode label; or

      -1 if no label number has been set

      Since:
      1.0
    • getLocalVars

      public ContinuationStack getLocalVars()
      [PRIVATE AND UNSUPPORTED] Retrieves the local variable stack of this continuation.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Returns:
      this continuation's local variable stack
      Since:
      1.0
    • getLocalStack

      public ContinuationStack getLocalStack()
      [PRIVATE AND UNSUPPORTED] Retrieves the local operand stack of this continuation.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Returns:
      this continuation's local operand stack
      Since:
      1.0
    • getId

      public String getId()
      Retrieves the continuation ID.

      Note that this ID is not necessarily present in the manager and that trying to retrieve a continuation afterward from its ID is never guaranteed to give a result.

      Returns:
      the unique ID of this continuation.
      Since:
      1.0
    • setParentId

      public void setParentId(String id)
      [PRIVATE AND UNSUPPORTED] Set the ID of this continuation's parent.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Parameters:
      id - the ID of this continuation's parent
      Since:
      1.0
      See Also:
    • getParentId

      public String getParentId()
      Retrieves the ID of this continuation's parent.
      Returns:
      the ID of this continuation's parent continuation; or

      null if this continuation has no parent.

      Since:
      1.0
    • addRelatedId

      public void addRelatedId(String id)
      [PRIVATE AND UNSUPPORTED] Associates the ID of another continuation to this continuation.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Parameters:
      id - the ID of another continuation that's related to this continuation
      Since:
      1.0
    • getContinuable

      public Object getContinuable()
      Returns the object instance in which this continuation was executing.
      Returns:
      this continuation's active object
      Since:
      1.0
    • setCreatedCallState

      public void setCreatedCallState(CallState createdCallState)
      Sets the call continuation's state when a new call continuation is created.

      This state initiates a call continuation and should be set when a new call happens, after that it should never be changed.

      Parameters:
      createdCallState - this call continuation's creation state
      Since:
      1.0
      See Also:
    • getCreatedCallState

      public CallState getCreatedCallState()
      Retrieves this continuation's call continuation creation state.

      If this returns a non-null value, you can detect from it that this was a call continuation.

      Returns:
      this continuation
      Since:
      1.0
      See Also:
    • setActiveCallState

      public void setActiveCallState(CallState callState)
      Sets the active call state for this continuation.

      This mainly passes on the call state that was created during a call continuation. It allows quick retrieval of the active call state when an answer occurs.

      Parameters:
      callState - the active call state
      Since:
      1.0
      See Also:
    • getActiveCallState

      public CallState getActiveCallState()
      Retrieves the call state that is active during this continuation.
      Returns:
      the active CallState; or

      null if no call state was active for this continuation

    • setCallAnswer

      public void setCallAnswer(Object answer)
      Set the answer to a call continuation.
      Parameters:
      answer - the object that will be the call continuation's answer; or null if there was no answer
      Since:
      1.0
    • clone

      [PRIVATE AND UNSUPPORTED] Creates a cloned instance of this continuation context, this clone is not a perfect copy but is intended to be a child continuation and all context data is set up for that.

      This method is used by the instrumented bytecode that provides continuations support, it's not intended for general use.

      Overrides:
      clone in class Object
      Returns:
      a clone of this continuation for use as a child continuation
      Throws:
      CloneNotSupportedException
      Since:
      1.0