Package com.coditory.sherlock
Class SherlockStub
- java.lang.Object
-
- com.coditory.sherlock.SherlockStub
-
-
Constructor Summary
Constructors Constructor Description SherlockStub()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.coditory.sherlock.DistributedLockBuilder<DistributedLock>
createLock()
Creates a distributed lock.com.coditory.sherlock.DistributedLockBuilder<DistributedLock>
createOverridingLock()
Create a distributed overriding lock.com.coditory.sherlock.DistributedLockBuilder<DistributedLock>
createReentrantLock()
Creates a distributed reentrant lock.boolean
forceReleaseAllLocks()
Force releases all acquired locks.void
initialize()
Initializes underlying infrastructure.static SherlockStub
withAcquiredLocks()
Make the stub produce acquired locks by defaultSherlockStub
withLock(DistributedLock lock)
Make the stub produce return a predefined lock.static SherlockStub
withReleasedLocks()
Make the stub produce released locks by default-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.coditory.sherlock.Sherlock
createLock, createOverridingLock, createReentrantLock, forceReleaseLock
-
-
-
-
Method Detail
-
withReleasedLocks
public static SherlockStub withReleasedLocks()
Make the stub produce released locks by default- Returns:
- the stub instance
-
withAcquiredLocks
public static SherlockStub withAcquiredLocks()
Make the stub produce acquired locks by default- Returns:
- the stub instance
-
withLock
public SherlockStub withLock(DistributedLock lock)
Make the stub produce return a predefined lock.- Parameters:
lock
- returned when creating a lock with the same id- Returns:
- the stub instance
-
initialize
public void initialize()
Description copied from interface:Sherlock
Initializes underlying infrastructure. If this method is not invoked explicitly then it can be invoked implicitly when acquiring or releasing a lock for the first time.Most often initialization is related with creating indexes and tables.
- Specified by:
initialize
in interfaceSherlock
-
createLock
public com.coditory.sherlock.DistributedLockBuilder<DistributedLock> createLock()
Description copied from interface:Sherlock
Creates a distributed lock. Created lock may be acquired only once by the same owner:assert lock.acquire() == true assert lock.acquire() == false
- Specified by:
createLock
in interfaceSherlock
- Returns:
- the lock builder
-
createReentrantLock
public com.coditory.sherlock.DistributedLockBuilder<DistributedLock> createReentrantLock()
Description copied from interface:Sherlock
Creates a distributed reentrant lock. Reentrant lock may be acquired multiple times by the same owner:assert reentrantLock.acquire() == true assert reentrantLock.acquire() == true
- Specified by:
createReentrantLock
in interfaceSherlock
- Returns:
- the reentrant lock builder
-
createOverridingLock
public com.coditory.sherlock.DistributedLockBuilder<DistributedLock> createOverridingLock()
Description copied from interface:Sherlock
Create a distributed overriding lock. Returned lock may acquire or release any other lock without checking its state:assert someLock.acquire() == true assert overridingLock.acquire() == true
It could be used for administrative actions.
- Specified by:
createOverridingLock
in interfaceSherlock
- Returns:
- the overriding lock builder
-
forceReleaseAllLocks
public boolean forceReleaseAllLocks()
Description copied from interface:Sherlock
Force releases all acquired locks.It could be used for administrative actions.
- Specified by:
forceReleaseAllLocks
in interfaceSherlock
- Returns:
- true if any lock was released
-
-