org.axonframework.repository
Class OptimisticLockManager

java.lang.Object
  extended by org.axonframework.repository.OptimisticLockManager
All Implemented Interfaces:
LockManager

public class OptimisticLockManager
extends Object
implements LockManager

Implementation of the LockManager that uses an optimistic locking strategy. It uses the sequence number of the last committed event to detect concurrent access.

Classes that use a repository with this strategy must implement any retry logic themselves. Use the ConcurrencyException to detect concurrent access.

Since:
0.3
Author:
Allard Buijze
See Also:
EventSourcedAggregateRoot, ConcurrencyException

Constructor Summary
OptimisticLockManager()
           
 
Method Summary
 void obtainLock(Object aggregateIdentifier)
          Obtain a lock for an aggregate with the given aggregateIdentifier.
 void releaseLock(Object aggregateIdentifier)
          Release the lock held for an aggregate with the given aggregateIdentifier.
 boolean validateLock(AggregateRoot aggregate)
          Make sure that the current thread holds a valid lock for the given aggregate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptimisticLockManager

public OptimisticLockManager()
Method Detail

validateLock

public boolean validateLock(AggregateRoot aggregate)
Make sure that the current thread holds a valid lock for the given aggregate.

Specified by:
validateLock in interface LockManager
Parameters:
aggregate - the aggregate to validate the lock for
Returns:
true if a valid lock is held, false otherwise

obtainLock

public void obtainLock(Object aggregateIdentifier)
Obtain a lock for an aggregate with the given aggregateIdentifier. Depending on the strategy, this method may return immediately or block until a lock is held.

Specified by:
obtainLock in interface LockManager
Parameters:
aggregateIdentifier - the identifier of the aggregate to obtains a lock for.

releaseLock

public void releaseLock(Object aggregateIdentifier)
Release the lock held for an aggregate with the given aggregateIdentifier. The caller of this method must ensure a valid lock was requested using LockManager.obtainLock(Object). If no lock was successfully obtained, the behavior of this method is undefined.

Specified by:
releaseLock in interface LockManager
Parameters:
aggregateIdentifier - the identifier of the aggregate to release the lock for.


Copyright © 2010-2016. All Rights Reserved.