Thanks very much Steven.
For my own future reference (I know I will end up asking myself this question again in the future), the classes you referred to are:
- Aggregate:
-
modelling:org.axonframework.modelling.command.LockingRepository
(abstract class) -
axon-eventsourcing:org.axonframework.eventsourcing.EventSourcingRepository
(extendsLockingRepository
) - you can see where the lock is obtained by searching:
lockFactory.obtainLock
inLockingRepository
.
-
- Saga:
-
modelling:org.axonframework.modelling.saga.repository.LockingSagaRepository
(abstract class) -
modelling:org.axonframework.modelling.saga.repository.AnnotatedSagaRepository
(extendsLockingSagaRepository
) - you can see where the lock is obtained by searching for invocations to the
lockSagaAccess
method in theLockingSagaRepository
(wheneverload
orcreateInstance
is called).
-
And so as I have understood it:
- Concurrent access to state within an aggregate/saga will never occur within the same JVM.
- This is because only one unit of work (within the same JVM process) can possess the lock for an aggregate/saga at a time.
- Other unit of work instances in the JVM for the same aggregate/saga may exist but they will block until they are able to grab the lock.
Is this an accurate summary?
(I’m assuming Axon framework defaults here i.e. Pessimistic Locking)