Class BasicContinuableRunner

java.lang.Object
rife.continuations.basic.BasicContinuableRunner

public class BasicContinuableRunner extends Object
Basic implementation of a 'continuable runner' that will execute the continuable objects and correctly handle the continuations-related exceptions that are triggered.

This runner is probably only applicable to the most simple of use-cases, but by reading its source it should be relatively easy to adapt of extend it for purposes that don't fall inside its scope.

Since:
1.0
  • Constructor Details

    • BasicContinuableRunner

      public BasicContinuableRunner(ContinuationConfigInstrument configInstrument, Class[] entryMethodArgumentTypes)
      Create a new runner instance.
      Parameters:
      configInstrument - the instance of the instrumentation configuration that will be used for the transformation
      entryMethodArgumentTypes - the array argument types that the entry method takes, for instance null if it takes none.
      Since:
      1.0
    • BasicContinuableRunner

      public BasicContinuableRunner(ContinuationConfigInstrument configInstrument, Class[] entryMethodArgumentTypes, ClassLoader classloader)
      Create a new runner instance with a custom classloader.
      Parameters:
      configInstrument - the instance of the instrumentation configuration that will be used for the transformation
      entryMethodArgumentTypes - the array argument types that the entry method takes, for instance null if it takes none.
      classloader - the classloader that will be used to load the continuable classes, this is for example an instance of BasicContinuableClassLoader
      Since:
      1.0
  • Method Details

    • start

      public String start(String className) throws Throwable
      Starts the execution of a new instance of the provided class.
      Parameters:
      className - the name of the class that will be executed
      Returns:
      the ID of the resulting paused continuation; or

      null if no continuation was paused

      Throws:
      Throwable - when an error occurs
      Since:
      1.0
    • start

      public String start(Class klass) throws Throwable
      Starts the execution of a new instance of the provided class.
      Parameters:
      klass - the class that will be executed
      Returns:
      the ID of the resulting paused continuation; or

      null if no continuation was paused

      Throws:
      Throwable - when an error occurs
      Since:
      1.0
    • start

      public String start(Object continuable) throws Throwable
      Starts the execution of a new instance of a continuable.
      Parameters:
      continuable - the instance that will be executed
      Returns:
      the ID of the resulting paused continuation; or

      null if no continuation was paused

      Throws:
      Throwable - when an error occurs
      Since:
      1.0
    • resume

      public String resume(String continuationId) throws Throwable
      Resumes the execution of a paused continuation.
      Parameters:
      continuationId - the ID of the continuation that will be resumed
      Returns:
      the ID of the resulting paused continuation; or

      null if no continuation was paused or if the provided ID couldn't be found

      Throws:
      Throwable - when an error occurs
      Since:
      1.0
    • answer

      public String answer(String continuationId, Object callAnswer) throws Throwable
      Resumes the execution of a call continuation.
      Parameters:
      continuationId - the ID of the continuation that will be resumed
      callAnswer - the call answer object
      Returns:
      the ID of the resulting paused continuation; or

      null if no continuation was paused or if the provided ID couldn't be found

      Throws:
      Throwable - when an error occurs
      Since:
      1.0
    • run

      public String run(String continuationId) throws Throwable
      Executes a continuation whether it's paused or not. This is supposed to only be used for answer continuations.
      Parameters:
      continuationId - the ID of the existing continuation context that will be executed
      Returns:
      the ID of the resulting paused continuation; or

      null if no continuation was paused or if the provided ID couldn't be found

      Throws:
      Throwable - when an error occurs
      Since:
      1.0
    • executeContinuable

      public void executeContinuable(Object object) throws Throwable
      Executes the continuable object by looking up the entrance method and invoking it.

      This method can be overridden in case the default behavior isn't appropriate.

      Parameters:
      object - the continuable that will be executed
      Throws:
      Throwable - when an unexpected error occurs
      Since:
      1.0
    • beforeExecuteEntryMethodHook

      public void beforeExecuteEntryMethodHook(Object object)
      Hook method that will be executed right before executing the entry method of a continuable object, when the default implementation of executeContinuable(java.lang.Object) is used.

      This can for example be used to inject a continuable support object in case the main continuable class only implements the marker interface without having any of the support methods (see ContinuationConfigInstrument.getContinuableSupportClassName()).

      Parameters:
      object - the continuable object that will be executed
      Since:
      1.0
      See Also:
    • getConfigInstrumentation

      public ContinuationConfigInstrument getConfigInstrumentation()
      Retrieves the instrumentation configuration that is used by this runner.
      Returns:
      this runner's instrumentation configuration
      Since:
      1.0
    • getEntryMethodArgumentTypes

      public Class[] getEntryMethodArgumentTypes()
      Retrieves the entry method argument types.
      Returns:
      the argument types that are used by the continuations entry method
      Since:
      1.2
    • getClassLoader

      public ClassLoader getClassLoader()
      Retrieves the classloader that is used by this runner.
      Returns:
      this runner's classloader
      Since:
      1.0
    • cloneContinuations

      public BasicContinuableRunner cloneContinuations(boolean cloneContinuations)
      Configures the runner to clone continuations or not.
      Parameters:
      cloneContinuations - true if continuations should be cloned when they are resumed; or

      false if they should not be cloned

      Returns:
      this runner instance
      Since:
      1.0
      See Also:
    • setCloneContinuations

      public void setCloneContinuations(boolean cloneContinuations)
      Configures the runner to clone continuations or not.
      Parameters:
      cloneContinuations - true if continuations should be cloned when they are resumed; or

      false if they should not be cloned

      Since:
      1.0
      See Also:
    • getCloneContinuations

      public boolean getCloneContinuations()
      Indicates whether continuations should be cloned when they are resumed.
      Returns:
      true if continuations should be cloned when they are resumed; or

      false if they should not be cloned

      Since:
      1.0
      See Also:
    • callTargetRetriever

      public BasicContinuableRunner callTargetRetriever(CallTargetRetriever callTargetRetriever)
      Sets the call target retriever that will be used when a call continuation is triggered.
      Parameters:
      callTargetRetriever - the call target retriever that will be used
      Returns:
      this runner instance
      Since:
      1.0
      See Also:
    • setCallTargetRetriever

      public void setCallTargetRetriever(CallTargetRetriever callTargetRetriever)
      Sets the call target retriever that will be used when a call continuation is triggered.
      Parameters:
      callTargetRetriever - the call target retriever that will be used
      Since:
      1.0
      See Also:
    • getCallTargetRetriever

      public CallTargetRetriever getCallTargetRetriever()
      Retrieves the call target retriever that will be used when a call continuation is triggered.
      Returns:
      this runner's call target retriever
      Since:
      1.0
      See Also:
    • getCurrentContinuable

      public Object getCurrentContinuable()
      Retrieves the continuable that is active for the executing thread.
      Returns:
      this thread's continuable; or

      null if there's no current continuable

      Since:
      1.0
    • getManager

      public ContinuationManager getManager()
      Retrieves the manager that is used by the continuation runner.
      Returns:
      this runner's continuation manager
      Since:
      1.0