Class AbstractDLock

    • Constructor Detail

      • AbstractDLock

        public AbstractDLock​(String name)
    • Method Detail

      • getName

        public String getName()
        Get lock's name(space).
        Specified by:
        getName in interface IDLock
        Returns:
      • updateLockHolder

        protected void updateLockHolder​(String clientId,
                                        long lockDurationMs)
        Update current lock's holder info.
        Parameters:
        clientId -
        lockDurationMs -
        Since:
        0.1.1
      • getClientId

        protected String getClientId()
        Get client-id who is currently holding the lock.

        Note: value returned from this method is "estimated".

        Returns:
        Since:
        0.1.1
      • setClientId

        protected AbstractDLock setClientId​(String clientId)
        Get client-id who is currently holding the lock.
        Parameters:
        clientId -
        Returns:
        Since:
        0.1.1
      • getTimestampExpiry

        protected long getTimestampExpiry()
        Get timestamp (in milliseconds) when the lock-acquisition expires.

        Note: value returned from this method is "estimated".

        Returns:
        Since:
        0.1.1
      • setTimestampExpiry

        protected AbstractDLock setTimestampExpiry​(long timestampExpiry)
        Get timestamp (in milliseconds) when the lock-acquisition expires.
        Parameters:
        timestampExpiry -
        Returns:
        Since:
        0.1.1
      • setLockProperties

        public AbstractDLock setLockProperties​(Properties lockProps)
        Lock's custom properties.
        Parameters:
        lockProps -
        Returns:
      • getLockProperties

        protected Properties getLockProperties()
        Get lock's custom properties.
        Returns:
      • getLockProperty

        protected String getLockProperty​(String key)
        Get lock's custom property.
        Parameters:
        key -
        Returns:
      • destroy

        public void destroy()
        Cleanup method.
      • lock

        public LockResult lock​(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.

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

        public 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.

        Specified by:
        lock in interface IDLock
        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

        public 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.

        Specified by:
        lock in interface IDLock
        Parameters:
        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