Class FallbackSequencingPolicy<E extends Exception>
java.lang.Object
org.axonframework.messaging.eventhandling.sequencing.FallbackSequencingPolicy<E>
- Type Parameters:
E- The type of exception to catch and handle.
- All Implemented Interfaces:
SequencingPolicy
public class FallbackSequencingPolicy<E extends Exception>
extends Object
implements SequencingPolicy
Implementation of
SequencingPolicy that provides exception-based fallback behavior. When the delegate
policy throws a specified exception type, this implementation will catch it and delegate to a fallback policy.
This allows for composing sequencing strategies where certain policies might fail with exceptions for unsupported event types, falling back to more generic approaches when exceptions occur.
- Since:
- 5.0.0
- Author:
- Mateusz Nowak
-
Constructor Summary
ConstructorsConstructorDescriptionFallbackSequencingPolicy(SequencingPolicy delegate, SequencingPolicy fallback, Class<E> exceptionType) Initializes a new instance with the givendelegatepolicy,fallbackpolicy, andexceptionTypeto catch. -
Method Summary
Modifier and TypeMethodDescriptiongetSequenceIdentifierFor(EventMessage event, ProcessingContext context) Returns the sequence identifier for the givenevent.
-
Constructor Details
-
FallbackSequencingPolicy
public FallbackSequencingPolicy(@Nonnull SequencingPolicy delegate, @Nonnull SequencingPolicy fallback, @Nonnull Class<E> exceptionType) Initializes a new instance with the givendelegatepolicy,fallbackpolicy, andexceptionTypeto catch.- Parameters:
delegate- The primary policy to attempt sequence identification with first, notnull.fallback- The fallback policy to use when the delegate throws the specified exception, notnull.exceptionType- The type of exception to catch from the delegate policy, notnull.- Throws:
NullPointerException- When any of the parameters isnull.
-
-
Method Details
-
getSequenceIdentifierFor
public Optional<Object> getSequenceIdentifierFor(@Nonnull EventMessage event, @Nonnull ProcessingContext context) Description copied from interface:SequencingPolicyReturns the sequence identifier for the givenevent. When two events 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 event.The
Optional#empty()should ONLY be returned when the policy cannot determine a sequence identifier for the given event. This typically happens when the policy is not applicable for the specific event type. WhenOptional#empty()is returned, it is up to the component using this policy to provide a default behavior, use another policy, or throw an exception / react in any other way - as appropriate.- Specified by:
getSequenceIdentifierForin interfaceSequencingPolicy- Parameters:
event- The event for which to get the sequencing identifier.context- The processing context in which the event is being handled. This instance of 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 event, or
Optional#empty()if this policy cannot determine a sequence identifier for the given event.
-