Class DistributedLockBuilder<T>

  • Type Parameters:
    T - lock type

    public final class DistributedLockBuilder<T>
    extends java.lang.Object
    Builds a distributed lock of type T.
    • Method Detail

      • withLockId

        public DistributedLockBuilder<T> withLockId​(java.lang.String lockId)
        Set up lock identifier. Lock identifier distinguishes locks in a distributed system.
        Parameters:
        lockId - the lock identifier
        Returns:
        the builder
      • withLockDuration

        public DistributedLockBuilder<T> withLockDuration​(java.time.Duration duration)
        Overrides the default lock duration. Lock duration is the amount time that must pass to lock expire the lock. Expired lock is treated as released.
        Parameters:
        duration - lock duration.
        Returns:
        the builder
      • withPermanentLockDuration

        public DistributedLockBuilder<T> withPermanentLockDuration()
        Overrides the default lock duration so the lock never expires.
        Returns:
        the builder
      • withOwnerId

        public DistributedLockBuilder<T> withOwnerId​(java.lang.String ownerId)
        Overrides the default owner id used to distinguish who acquired the lock.
        Parameters:
        ownerId - owner identifier
        Returns:
        the builder
      • withUniqueOwnerId

        public DistributedLockBuilder<T> withUniqueOwnerId()
        Overrides the default owner id policy. Created lock will have random and unique id.
        Returns:
        the builder
      • withStaticUniqueOwnerId

        public DistributedLockBuilder<T> withStaticUniqueOwnerId()
        Overrides the default owner id policy. Created lock will have random identifier shared by all lock instances created in this JVM. Think of it as a static random value.
        Returns:
        the builder
      • build

        public T build()
        Builds the lock.
        Returns:
        the lock