
io.mongock.driver.api.lock.LockManager Maven / Gradle / Ivy
package io.mongock.driver.api.lock;
import java.io.Closeable;
public interface LockManager extends Closeable {
/**
* @return lock's key
*/
default String getDefaultKey() {
return "DEFAULT_LOCK";
}
/**
* Tries to acquire the default lock regardless who is the current owner.
* If the lock is already acquired by the current LockChecker or is expired, will be updated
* In case the lock is acquired by another LockChecker, it will wait until the current lock is expired
* and will try to acquire it again. This will be repeated as many times as (maxTries - 1)
*
* @throws LockCheckException if the lock cannot be acquired
*/
void acquireLockDefault() throws LockCheckException;
/**
* Tries to refresh the default lock when the current LockChecker has the lock or , when the lock
* is expired, is the last owner
* Notice that it does not try to acquire when is acquired by another LockChecker
*
* @throws LockCheckException if, in case of needed, the lock cannot be refreshed
*/
void ensureLockDefault() throws LockCheckException;
/**
* Release the default lock when is acquired by the current LockChecker.
* When the lock is not acquired by the current LockChecker, it won't make any change.
* Does not throw any exception neither.
* Idempotent operation.
*/
void releaseLockDefault();
/**
* If the flag 'waitForLog' is set, indicates the maximum time it will wait for the lock in total.
*
* @param millis max waiting time for lock. Must be greater than 0
* @return LockChecker object for fluent interface
*/
LockManager setLockQuitTryingAfterMillis(long millis);
/**
* @return lock try frequency
*/
long getLockTryFrequency();
/**
* Updates the maximum number of tries to acquire the lock, if the flag 'waitForLog' is set
* Default 1
*
* @param millis number of tries
* @return LockChecker object for fluent interface
*/
LockManager setLockTryFrequencyMillis(long millis);
/**
* Indicates the number of milliseconds the lock will be acquired for
* Default 3 minutes
*
* @param lockAcquiredForMillis milliseconds the lock will be acquired for
* @return LockChecker object for fluent interface
*/
LockManager setLockAcquiredForMillis(long lockAcquiredForMillis);
/**
* @return Lock's owner
*/
String getOwner();
/**
* @return if lock is held
*/
boolean isLockHeld();
/**
* force to delete all the locks in the database. Mainly for test environment. Not recommended production use
*/
void clean();
@Override
void close();
}