Class Scope

java.lang.Object
org.axonframework.messaging.Scope
Direct Known Subclasses:
AggregateLifecycle, SagaLifecycle

public abstract class Scope extends Object
Describes functionality off processes which can be 'in scope', like an Aggregate or Saga.
Since:
3.3
Author:
Steven van Beelen
  • Constructor Details

    • Scope

      public Scope()
  • Method Details

    • getCurrentScope

      public static <S extends Scope> S getCurrentScope() throws IllegalStateException
      Retrieve the current Scope.
      Type Parameters:
      S - a type implementing Scope
      Returns:
      the current Scope
      Throws:
      IllegalStateException - in case no current Scope is active, in which case #startScope() should be called first
    • describeCurrentScope

      public static ScopeDescriptor describeCurrentScope()
      Provide a description of the current Scope.
      Returns:
      a ScopeDescriptor describing the current Scope
    • startScope

      protected void startScope()
      Start a Scope by adding this to a Deque contained in a ThreadLocal.
    • endScope

      protected void endScope()
      End a Scope by removing this from a Deque contained in a ThreadLocal. If this isn't on the top of the Deque, an IllegalStateException will be thrown, as that signals a process is trying to end somebody else's scope. If the Deque is empty, it will be removed from the ThreadLocal.
    • executeWithResult

      protected <V> V executeWithResult(Callable<V> task) throws Exception
      Scope instance method to execute given task of type Callable in the context of this Scope. This updates the thread's current scope before executing the task. If a scope is already registered with the current thread that one will be temporarily replaced with this scope until the task completes. This method returns the execution result of the task.
      Type Parameters:
      V - the type of execution result of the task
      Parameters:
      task - the task to execute of type Callable
      Returns:
      the execution result of type V
      Throws:
      Exception - if executing the task results in an exception
    • describeScope

      public abstract ScopeDescriptor describeScope()
      Provide a description of this Scope.
      Returns:
      a ScopeDescriptor describing this Scope