Package org.graylog2.cluster.lock
Class RefreshingLockService
java.lang.Object
org.graylog2.cluster.lock.RefreshingLockService
- All Implemented Interfaces:
AutoCloseable
Service that can be used to acquire a
Lock that will be refreshed periodically in a background thread.
Each instance of the service needs to be closed to release the lock.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionRefreshingLockService(LockService lockService, ScheduledExecutorService scheduler, Duration lockTTL) -
Method Summary
Modifier and TypeMethodDescriptionvoidacquireAndKeepLock(String resource, int maxConcurrency) Lock the given resource and ensure that only the given number of locks for the resource exist in the cluster.voidacquireAndKeepLock(String resource, String lockContext) Lock the given resource exclusively.voidclose()Release the lock.voidRelease the lock.
-
Constructor Details
-
RefreshingLockService
@Inject public RefreshingLockService(LockService lockService, @Named("daemonScheduler") ScheduledExecutorService scheduler, @Named("lock_service_lock_ttl") Duration lockTTL)
-
-
Method Details
-
acquireAndKeepLock
Lock the given resource and ensure that only the given number of locks for the resource exist in the cluster.- Parameters:
resource- the resource to lockmaxConcurrency- maximum number of locks for the resource- Throws:
AlreadyLockedException- when the resource couldn't be locked
-
acquireAndKeepLock
Lock the given resource exclusively.- Parameters:
resource- the resource to locklockContext- the identifier for the exclusive lock- Throws:
AlreadyLockedException- when the resource couldn't be locked
-
releaseLock
public void releaseLock()Release the lock. -
close
public void close()Release the lock.- Specified by:
closein interfaceAutoCloseable
-