Package org.axonframework.messaging.core
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 ClassesModifier and TypeInterfaceDescriptionstatic final classObject that is used as a key to retrieve and register resources of a given type in aContext. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsResource(Context.ResourceKey<?> key) Indicates whether a resource has been registered with the givenkeyin this Context.static Contextempty()Creates an empty Context.<T> TgetResource(Context.ResourceKey<T> key) Returns the resource currently registered under the givenkey, ornullif no resource is present.Retrieves all resources contained within the currentContext.static <T> Contextwith(Context.ResourceKey<T> key, T value) Create a Context with a single resource with the given initialkeyandvalue.<T> ContextwithResource(Context.ResourceKey<T> key, T resource) Constructs a copy ofthisContext with an additionalresourcefor givenkey.
-
Method Details
-
with
Create a Context with a single resource with the given initialkeyandvalue.- 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
Creates an empty Context.- Returns:
- A Context with no resources assigned to it.
-
containsResource
Indicates whether a resource has been registered with the givenkeyin this Context.- Parameters:
key- The key of the resource to check.- Returns:
trueif a resource is registered with thiskey, otherwisefalse.
-
getResource
Returns the resource currently registered under the givenkey, ornullif no resource is present.- Type Parameters:
T- The type of resource registered under the givenkey.- Parameters:
key- The key to retrieve the resource for.- Returns:
- The resource currently registered under given
key, ornullif not present.
-
withResource
Constructs a copy ofthisContext with an additionalresourcefor givenkey.- Type Parameters:
T- The type of resource registered under the givenkey.- Parameters:
key- The key under which to register theresource.resource- The resource to register.- Returns:
- A copy of
thisContext with the added givenresourcesunder the givenkeyto the copy.
-
resources
Retrieves all resources contained within the currentContext.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
Contextinstances, not for retrieval. For that, there's thegetResource(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.
-