Interface LockManager<T>

  • All Superinterfaces:
    java.lang.AutoCloseable

    public interface LockManager<T>
    extends java.lang.AutoCloseable
    Controller for acquiring distributed lock on resources.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<ResourceLock<T>> acquireLock​(java.lang.String path, T value)
      Acquire a lock on a shared resource.
      java.util.concurrent.CompletableFuture<java.lang.Void> asyncClose()
      Close the LockManager and release all the locks.
      java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> listLocks​(java.lang.String path)
      List all the locks that are children of a specific path.
      java.util.concurrent.CompletableFuture<java.util.Optional<T>> readLock​(java.lang.String path)
      Read the content of an existing lock.
      • Methods inherited from interface java.lang.AutoCloseable

        close
    • Method Detail

      • readLock

        java.util.concurrent.CompletableFuture<java.util.Optional<T>> readLock​(java.lang.String path)
        Read the content of an existing lock. If the lock is already taken, this operation will fail immediately. Warning: because of the distributed nature of the lock, having acquired a lock will never provide a strong guarantee that no one else also think it owns the same resource. The caller will have to deal with these race conditions when using the resource itself (eg. using compareAndSet() or fencing mechanisms).
        Parameters:
        path - the path of the resource on which to acquire the lock
        Returns:
        a future that will track the completion of the operation
        Throws:
        MetadataStoreException.NotFoundException - if the lock is not taken
        MetadataStoreException - if there's a failure in reading the lock
      • acquireLock

        java.util.concurrent.CompletableFuture<ResourceLock<T>> acquireLock​(java.lang.String path,
                                                                            T value)
        Acquire a lock on a shared resource. If the lock is already taken, this operation will fail immediately. Warning: because of the distributed nature of the lock, having acquired a lock will never provide a strong guarantee that no one else also think it owns the same resource. The caller will have to deal with these race conditions when using the resource itself (eg. using compareAndSet() or fencing mechanisms).
        Parameters:
        path - the path of the resource on which to acquire the lock
        value - the value of the lock
        Returns:
        a future that will track the completion of the operation
        Throws:
        MetadataStoreException.LockBusyException - if the lock is already taken
        MetadataStoreException - if there's a failure in acquiring the lock
      • listLocks

        java.util.concurrent.CompletableFuture<java.util.List<java.lang.String>> listLocks​(java.lang.String path)
        List all the locks that are children of a specific path. For example, given locks: /a/b/lock-1 and /a/b/lock-2, the listLocks("/a/b") will return a list of ["lock-1", "lock-2"].
        Parameters:
        path - the prefix path to get the list of locks
        Returns:
        a future that will track the completion of the operation
        Throws:
        MetadataStoreException - if there's a failure in getting the list of locks
      • asyncClose

        java.util.concurrent.CompletableFuture<java.lang.Void> asyncClose()
        Close the LockManager and release all the locks.
        Returns:
        a future that will track the completion of the operation
        Throws:
        MetadataStoreException - if there's a failure in closing the LockManager