Interface IDLock

  • All Known Implementing Classes:
    AbstractDLock, BaseRedisDLock, ClusteredRedisDLock, InmemDLock, RedisDLock

    public interface IDLock
    Distributed lock interface.

    Implementation:

    • Each lock is identified by a unique name(space).
    • Within a name(space), only one client is allowed to hold lock as a given time; each client is identified by a unique client-id (within the namespace).

    Since:
    0.1.0
    Author:
    Thanh Nguyen
    • Field Detail

    • Method Detail

      • getName

        String getName()
        Get lock's name(space).
        Returns:
      • lock

        LockResult lock​(String clientId,
                        long lockDurationMs)
        Acquire the lock for clientId for a duration of lockDurationMs.

        Reentrant: lock can be acquired multiple times by the same clientId. Lock's expiry will be extended accordingly.

        Parameters:
        clientId - within a namespace, only one client is allowed to hold the lock as a given time
        lockDurationMs -
        Returns:
        LockResult.SUCCESSFUL if successful, LockResult.HOLD_BY_ANOTHER_CLIENT if lock is currently hold by another client
      • lock

        LockResult lock​(int waitWeight,
                        String clientId)
        Acquire the lock for clientId with default duration.

        Reentrant: lock can be acquired multiple times by the same clientId. Lock's expiry will be extended accordingly.

        Parameters:
        waitWeight - "fairness": clientId with higher waitWeight value might have higher chance to acquire the lock, negative value means "no fairness"
        clientId - within a namespace, only one client is allowed to hold the lock as a given time
        Returns:
        LockResult.SUCCESSFUL if successful, LockResult.HOLD_BY_ANOTHER_CLIENT if lock is currently hold by another client
        Since:
        0.1.2
      • lock

        LockResult lock​(int waitWeight,
                        String clientId,
                        long lockDurationMs)
        Acquire the lock for clientId for a duration of lockDurationMs.

        Reentrant: lock can be acquired multiple times by the same clientId. Lock's expiry will be extended accordingly.

        Parameters:
        waitWeight - "fairness": clientId with higher waitWeight value might have higher chance to acquire the lock, negative value means "no fairness"
        clientId - within a namespace, only one client is allowed to hold the lock as a given time
        lockDurationMs -
        Returns:
        LockResult.SUCCESSFUL if successful, LockResult.HOLD_BY_ANOTHER_CLIENT if lock is currently hold by another client
        Since:
        0.1.2