Interface ProcessingContext

All Superinterfaces:
ApplicationContext, Context, ProcessingLifecycle
All Known Implementing Classes:
LegacyMessageSupportingContext, ResourceOverridingProcessingContext

public interface ProcessingContext extends ProcessingLifecycle, ApplicationContext, Context
Implementation of the ProcessingLifecycle adding mutable resource management operations by implementing Context.

It is recommended to construct a Context.ResourceKey instance when adding/updating/removing resources from the ProcessingContext 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
  • Method Details

    • withResource

      default <T> ProcessingContext withResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource)
      Constructs a new ProcessingContext, branching off from this ProcessingContext.

      The given resource as added to the branched ProcessingContext under the given key.

      Specified by:
      withResource in interface Context
      Type Parameters:
      T - The type of resource associated with the key.
      Parameters:
      key - The key under which to register the resource in the branched ProcessingContext.
      resource - The resource to register in the branched ProcessingContext.
      Returns:
      A new ProcessingContext, branched off from this ProcessingContext.
    • putResource

      <T> T putResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource)
      Register the given resource under the given key.
      Type Parameters:
      T - The type of resource to register under given @code.
      Parameters:
      key - The key under which to register the resource.
      resource - The resource to register.
      Returns:
      The previously registered resource, or null if none was present.
    • updateResource

      <T> T updateResource(@Nonnull Context.ResourceKey<T> key, @Nonnull UnaryOperator<T> resourceUpdater)
      Update the resource with given key using the given resourceUpdater to describe the update. If no resource is registered with the given key, the resourceUpdater is invoked with null. Otherwise, the function is called with the currently registered resource under that key.

      The resource is replaced with the return value of the function, or removed when the function returns null.

      If the function throws an exception, the exception is rethrown to the caller.

      Type Parameters:
      T - The type of resource to update.
      Parameters:
      key - The key to update the resource for.
      resourceUpdater - The function performing the update itself.
      Returns:
      The new value associated with the key, or null when removed.
    • putResourceIfAbsent

      <T> T putResourceIfAbsent(@Nonnull Context.ResourceKey<T> key, @Nonnull T resource)
      Register the given instance under the given key if no value is currently present.
      Type Parameters:
      T - The type of resource to register under given key.
      Parameters:
      key - The key under which to register the resource.
      resource - The resource to register when nothing is present for the given key.
      Returns:
      The resource previously associated with given key.
    • computeResourceIfAbsent

      <T> T computeResourceIfAbsent(@Nonnull Context.ResourceKey<T> key, @Nonnull Supplier<T> resourceSupplier)
      If no resource is present for the given key, the given resourceSupplier is used to supply the instance to register under this key.
      Type Parameters:
      T - The type of resource registered under given key.
      Parameters:
      key - The key to register the resource for.
      resourceSupplier - The function to supply the resource to register.
      Returns:
      The resource associated with the key.
    • removeResource

      <T> T removeResource(@Nonnull Context.ResourceKey<T> key)
      Removes the resource registered under given key.
      Type Parameters:
      T - The type of resource associated with the key.
      Parameters:
      key - The key to remove the registered resource for.
      Returns:
      The value previously associated with the key.
    • removeResource

      <T> boolean removeResource(@Nonnull Context.ResourceKey<T> key, @Nonnull T expectedResource)
      Remove the resource associated with given key if the given expectedResource is the currently associated value.
      Type Parameters:
      T - The type of resource associated with the key.
      Parameters:
      key - The key to remove the registered resource for.
      expectedResource - The expected resource to remove.
      Returns:
      true if the resource has been removed, otherwise false.