Class SimpleContext

java.lang.Object
org.axonframework.messaging.core.SimpleContext
All Implemented Interfaces:
Context

public class SimpleContext extends Object implements Context
Implementation of the Context providing a basic implementation for context-specific resource management.
Since:
5.0.0
Author:
Steven van Beelen
  • Constructor Details

    • SimpleContext

      public SimpleContext(Context.ResourceKey<T> key, T value)
      Constructs a SimpleContext with a single resource.
      Type Parameters:
      T - The type of the initial resource
      Parameters:
      key - The key of the initial resource
      value - The initial resource
  • Method Details

    • containsResource

      public boolean containsResource(@Nonnull Context.ResourceKey<?> key)
      Description copied from interface: Context
      Indicates whether a resource has been registered with the given key in this Context.
      Specified by:
      containsResource in interface Context
      Parameters:
      key - The key of the resource to check.
      Returns:
      true if a resource is registered with this key, otherwise false.
    • getResource

      public <T> T getResource(@Nonnull Context.ResourceKey<T> key)
      Description copied from interface: Context
      Returns the resource currently registered under the given key, or null if no resource is present.
      Specified by:
      getResource in interface Context
      Type Parameters:
      T - The type of resource registered under the given key.
      Parameters:
      key - The key to retrieve the resource for.
      Returns:
      The resource currently registered under given key, or null if not present.
    • withResource

      public <T> Context withResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource)
      Description copied from interface: Context
      Constructs a copy of this Context with an additional resource for given key.
      Specified by:
      withResource in interface Context
      Type Parameters:
      T - The type of resource registered under the given key.
      Parameters:
      key - The key under which to register the resource.
      resource - The resource to register.
      Returns:
      A copy of this Context with the added given resources under the given key to the copy.
    • resources

      public Map<Context.ResourceKey<?>,Object> resources()
      Description copied from interface: Context
      Retrieves all resources contained within the current Context.

      Most of the time, none of the keys make any sense to the component that would retrieve them. Thus, this method is purely here for copying resources between Context instances, not for retrieval. For that, there's the Context.getResource(ResourceKey) method.

      Specified by:
      resources in interface Context
      Returns:
      A map containing all resources where each entry has a ResourceKey<?> as the key and the associated resource object as the value.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object