Class DefaultConflictResolver
java.lang.Object
org.axonframework.eventsourcing.conflictresolution.DefaultConflictResolver
- All Implemented Interfaces:
ConflictResolver
Implementation of a
ConflictResolver that fetches any unseen changes from the EventStore.- Author:
- Rene de Waele
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultConflictResolver(EventStore eventStore, String aggregateIdentifier, long expectedVersion, long actualVersion) Initializes aDefaultConflictResolverusing the giveneventStoreto load unseen events since givenexpectedVersion. -
Method Summary
Modifier and TypeMethodDescription<T extends Exception>
voiddetectConflicts(Predicate<List<DomainEventMessage<?>>> predicate, ContextAwareConflictExceptionSupplier<T> exceptionSupplier) Resolve conflicts between unseen changes made to the aggregate and new changes that are about to be made.voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.eventsourcing.conflictresolution.ConflictResolver
detectConflicts, detectConflicts
-
Constructor Details
-
DefaultConflictResolver
public DefaultConflictResolver(EventStore eventStore, String aggregateIdentifier, long expectedVersion, long actualVersion) Initializes aDefaultConflictResolverusing the giveneventStoreto load unseen events since givenexpectedVersion.- Parameters:
eventStore- the event store to load unseen eventsaggregateIdentifier- the identifier of the event sourced aggregate that is being modifiedexpectedVersion- the last seen version (sequence number) of the aggregateactualVersion- the actual version (sequence number) of the aggregate
-
-
Method Details
-
detectConflicts
public <T extends Exception> void detectConflicts(Predicate<List<DomainEventMessage<?>>> predicate, ContextAwareConflictExceptionSupplier<T> exceptionSupplier) throws T Description copied from interface:ConflictResolverResolve conflicts between unseen changes made to the aggregate and new changes that are about to be made.Conflicts are detected using the given
predicate. If thePredicate.test(Object)method returnstruea conflict is registered. If a conflict is registered an instance ofConflictingModificationException(or subtype) is thrown immediately. The cause of the exception is supplied by the givencauseSupplier(supplying anullcause is allowed).- Specified by:
detectConflictsin interfaceConflictResolver- Parameters:
predicate- test for conflicting unseen changes. Returnstrueif there is a conflict.exceptionSupplier- exception to throw when a conflict is detected- Throws:
T- The type of exception to throw when conflicts are detected
-
ensureConflictsResolved
public void ensureConflictsResolved()Ensure that conflicts have been resolved (via (detectConflicts(java.util.function.Predicate<java.util.List<org.axonframework.eventhandling.DomainEventMessage<?>>>, org.axonframework.eventsourcing.conflictresolution.ContextAwareConflictExceptionSupplier<T>)). If not, an instance ofConflictingModificationException(or subtype) should be thrown if there have been any unseen changes.
-