Class RefreshingLockService

java.lang.Object
org.graylog2.cluster.lock.RefreshingLockService
All Implemented Interfaces:
AutoCloseable

public class RefreshingLockService extends Object implements 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.
  • Constructor Details

  • Method Details

    • acquireAndKeepLock

      public void acquireAndKeepLock(String resource, int maxConcurrency) throws AlreadyLockedException
      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 lock
      maxConcurrency - maximum number of locks for the resource
      Throws:
      AlreadyLockedException - when the resource couldn't be locked
    • acquireAndKeepLock

      public void acquireAndKeepLock(String resource, String lockContext) throws AlreadyLockedException
      Lock the given resource exclusively.
      Parameters:
      resource - the resource to lock
      lockContext - 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:
      close in interface AutoCloseable