Interface Context

All Known Subinterfaces:
MessageStream.Entry<M>, ProcessingContext
All Known Implementing Classes:
LegacyMessageSupportingContext, ResourceOverridingProcessingContext, SimpleContext, SimpleEntry

public interface Context
Interface describing operations for context-specific, immutable, resource management.

It is recommended to construct a Context.ResourceKey instance when adding/updating resources from the Context to allow cross-referral by sharing the key or personalization when the resource should be private to a specific service.

Since:
5.0.0
Author:
Allard Buijze, Gerard Klijs, Milan Savić, Mitchell Herrijgers, Sara Pellegrini, Steven van Beelen
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    Object that is used as a key to retrieve and register resources of a given type in a Context.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Indicates whether a resource has been registered with the given key in this Context.
    static Context
    Creates an empty Context.
    <T> T
    Returns the resource currently registered under the given key, or null if no resource is present.
    Retrieves all resources contained within the current Context.
    static <T> Context
    with(Context.ResourceKey<T> key, T value)
    Create a Context with a single resource with the given initial key and value.
    <T> Context
    withResource(Context.ResourceKey<T> key, T resource)
    Constructs a copy of this Context with an additional resource for given key.
  • Method Details

    • with

      static <T> Context with(Context.ResourceKey<T> key, T value)
      Create a Context with a single resource with the given initial key and value.
      Type Parameters:
      T - The type of the initial resource.
      Parameters:
      key - The key to add to the newly created Context.
      value - The value to assign to given key.
      Returns:
      A Context with a single resource.
    • empty

      static Context empty()
      Creates an empty Context.
      Returns:
      A Context with no resources assigned to it.
    • containsResource

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

      <T> T getResource(@Nonnull Context.ResourceKey<T> key)
      Returns the resource currently registered under the given key, or null if no resource is present.
      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

      <T> Context withResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource)
      Constructs a copy of this Context with an additional resource for given key.
      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

      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 getResource(ResourceKey) method.

      Returns:
      A map containing all resources where each entry has a ResourceKey<?> as the key and the associated resource object as the value.