Class HierarchicalSequencingPolicy<M extends Message>
java.lang.Object
org.axonframework.messaging.core.sequencing.HierarchicalSequencingPolicy<M>
- Type Parameters:
M- the type of message to sequence
- All Implemented Interfaces:
SequencingPolicy<M>
public class HierarchicalSequencingPolicy<M extends Message>
extends Object
implements SequencingPolicy<M>
Implementation of
SequencingPolicy that combines two policies in a fallback pattern. When the primary policy
fails to determine a sequence identifier for a message (returns Optional.empty()), this implementation will
delegate to a secondary fallback policy.
This allows for composing sequencing strategies where certain message types might be handled by specialized policies, falling back to more generic approaches when specialized sequencing fails.
- Since:
- 5.0.0
- Author:
- Mateusz Nowak
-
Constructor Summary
ConstructorsConstructorDescriptionHierarchicalSequencingPolicy(SequencingPolicy<? super M> primary, SequencingPolicy<? super M> secondary) Initializes a new instance with the given primarydelegateandfallbackpolicies. -
Method Summary
Modifier and TypeMethodDescriptionsequenceIdentifierFor(M message, ProcessingContext context) Returns the sequence identifier for the givenmessage.
-
Constructor Details
-
HierarchicalSequencingPolicy
public HierarchicalSequencingPolicy(SequencingPolicy<? super M> primary, SequencingPolicy<? super M> secondary) Initializes a new instance with the given primarydelegateandfallbackpolicies.- Parameters:
primary- The primary policy to attempt sequence identification with first, notnull.secondary- The fallback policy to use when the delegate fails, notnull.- Throws:
NullPointerException- When either thedelegateorfallbackisnull.
-
-
Method Details
-
sequenceIdentifierFor
Description copied from interface:SequencingPolicyReturns the sequence identifier for the givenmessage. When two messages have the same identifier (as defined by their equals method), they will be executed sequentially. AOptional#empty()value indicates that there are no sequencing requirements for the handling of this message.The
Optional#empty()should only be returned when the policy cannot determine a sequence identifier for the given message. This typically happens when the policy is not applicable for the specific message type. WhenOptional#empty()is returned, it is up to the component using this policy to provide a default behavior, use another policy, throw an exception or react in any other way - as appropriate.- Specified by:
sequenceIdentifierForin interfaceSequencingPolicy<M extends Message>- Parameters:
message- the message for which to get the sequencing identifier.context- the processing context in which the message is being handled. There might be limitations to the instance of theProcessingContextdepending on where theSequencingPolicyis being applied. When handling Events for example, theProcessingContextdoesn't allow you to register phases actions by for exampleProcessingLifecycle.on(org.axonframework.messaging.core.unitofwork.ProcessingLifecycle.Phase, java.util.function.Function<org.axonframework.messaging.core.unitofwork.ProcessingContext, java.util.concurrent.CompletableFuture<?>>)or retrieving components byApplicationContext.component(java.lang.Class<C>).- Returns:
- a sequence identifier for the given message, or
Optional#empty()if this policy cannot determine a sequence identifier for the given message.
-