Interface AsyncLockCallback
-
public interface AsyncLockCallback
Callback for asynchronous locking operations.Instances of this interface can be passed to the
DistributedLock.lockAsync(Executor, AsyncLockCallback)
method in order to get asynchronous notifications about lock status changes. Method of this interface are executed as follows:- If locking attempt was successful then
onLockAcquire(DistributedLock)
method gets called. The acquired lock will be bound to the context of a callback thread (i.e.DistributedLock.isHeldByCurrentThread()
will returntrue
if called from the callback). Note that locks are not automatically released and it is up the callback implementation to decide when lock should bereleased
. After lock gets released then theonLockRelease(DistributedLock)
method will be called. - If locking attempt failed because of the lock is being held by some other node/thread then
onLockBusy(LockOwnerInfo)
method will be called and another attempt to acquire the lock will be preform unless the lock gets acquired or operation gets cancelled. - If callback is still waiting for the lock and lock owner changes then
onLockOwnerChange(LockOwnerInfo)
method will be notified and another attempt to acquire the lock will be preformed unless lock gets acquired or operation gets cancelled.
- If locking attempt was successful then
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
onLockAcquire(DistributedLock lock)
Gets called when lock was successfully acquired.default void
onLockBusy(LockOwnerInfo owner)
Gets called when initial attempt to acquire the lock failed because of the lock is being held by some other node or thread.default void
onLockOwnerChange(LockOwnerInfo owner)
Gets called when lock owner changes while the callback is still waiting for the lock to be acquired.default void
onLockRelease(DistributedLock lock)
Gets called after lock has been released.
-
-
-
Method Detail
-
onLockAcquire
void onLockAcquire(DistributedLock lock)
Gets called when lock was successfully acquired.The acquired lock is
bound
to the thread that calls this method (i.e.DistributedLock.isHeldByCurrentThread()
will returntrue
if called within this method). Note that lock will NOT be automatically released after this methods finishes its execution. It is up to the implementation to decide when lock should bereleased
.- Parameters:
lock
- Lock.
-
onLockBusy
default void onLockBusy(LockOwnerInfo owner)
Gets called when initial attempt to acquire the lock failed because of the lock is being held by some other node or thread.Note that lock will still remain in a waiting state after this method gets called and once the lock gets acquired then the
onLockAcquire(DistributedLock)
method will be called.- Parameters:
owner
- Current lock owner.
-
onLockOwnerChange
default void onLockOwnerChange(LockOwnerInfo owner)
Gets called when lock owner changes while the callback is still waiting for the lock to be acquired.Note that lock will still remain in a waiting state after this method gets called and once the lock gets acquired then the
onLockAcquire(DistributedLock)
method will be called.- Parameters:
owner
- New lock owner.
-
onLockRelease
default void onLockRelease(DistributedLock lock)
Gets called after lock has been released. Note that this method gets called only if the lock was previouslyacquired
.- Parameters:
lock
- Released lock.
-
-