Interface LockService

All Known Implementing Classes:
MongoLockService

public interface LockService
  • Method Details

    • lock

      Optional<Lock> lock(@Nonnull String resource, @Nullable String lockContext)
      Request a lock. If a lock already exists, the lock expiry time will be extended.
      Parameters:
      resource - Unique identifier for the resource that should be guarded by this lock.
      lockContext - an identifier that will be appended to the callers' node id. This will create the lock owner string. A context can be used for resources that should only allow a single lock to be acquired, even from the same node. If the lockContext is null, only the nodeId will be used.
      Returns:
      A Lock object, if a lock was obtained. An empty Optional, if no lock could be acquired.
    • lock

      Optional<Lock> lock(@Nonnull String resource)
      Request a lock. If a lock already exists, the lock expiry time will be extended.
      Parameters:
      resource - Unique identifier for the resource that should be guarded by this lock.
      Returns:
      A Lock object, if a lock was obtained. An empty Optional, if no lock could be acquired.
    • extendLock

      Optional<Lock> extendLock(@Nonnull Lock existingLock)
      Extend the expiry time of an existing lock.
      Parameters:
      existingLock - the lock that should be extended.
      Returns:
      A Lock object, if the lock could be extended. An empty Optional, if no lock extension could be acquired.
    • unlock

      Optional<Lock> unlock(@Nonnull String resource, @Nullable String lockContext)
      Unlock an existing lock.
      Parameters:
      resource - Unique identifier for the resource that was guarded by this lock.
      lockContext - the lockContext that was used to guard this lock.
      Returns:
      A Lock object, if the lock could be unlocked. An empty Optional, if no lock was found.
    • unlock

      Optional<Lock> unlock(Lock lock)
      Unlock an existing lock.
      Parameters:
      lock - The lock to unlock.
      Returns:
      A Lock object, if the lock could be unlocked. An empty Optional, if no lock was found.