@Override
    public LockResult lock(int waitWeight, String clientId, long lockDurationMs) {
        if (StringUtils.isBlank(clientId)) {
            throw new IllegalArgumentException("Invalid ClientID!");
        }
        if (lockDurationMs <= 0) {
            throw new IllegalArgumentException("Lock duration must be greater than zero!");
        }

        if (waitWeight >= 0) {
            synchronized (pQueue) {
                pQueue.add(new Token(clientId, waitWeight));
            }
        }
        synchronized (this) {
            try {
                if (waitWeight >= 0) {
                    Token token = pQueue.peek();
                    if (token != null && !StringUtils.equals(token.clientId, clientId)) {
                        return LockResult.HOLD_BY_ANOTHER_CLIENT;
                    }
                }
                if (!StringUtils.isBlank(getClientId())
                        && getTimestampExpiry() >= System.currentTimeMillis()
                        && !StringUtils.equals(getClientId(), clientId)) {
                    return LockResult.HOLD_BY_ANOTHER_CLIENT;
                }
                updateLockHolder(clientId, lockDurationMs);
                if (waitWeight >= 0) {
                    synchronized (pQueue) {
                        pQueue.clear();
                    }
                }
                return LockResult.SUCCESSFUL;
            } catch (Exception e) {
                throw e instanceof DLockException ? (DLockException) e : new DLockException(e);
            }
        }
    }
@ Override public LockResult lock ( int waitWeight , String clientId , long lockDurationMs ) { if ( StringUtils . isBlank ( clientId ) ) { throw new IllegalArgumentException ( "Invalid ClientID!" ) ; } if ( lockDurationMs <= 0 ) { throw new IllegalArgumentException ( "Lock duration must be greater than zero!" ) ; } if ( waitWeight >= 0 ) { synchronized ( pQueue ) { pQueue . add ( new Token ( clientId , waitWeight ) ) ; } } synchronized ( this ) { try { if ( waitWeight >= 0 ) { Token token = pQueue . peek ( ) ; if ( token != null && ! StringUtils . equals ( token . clientId , clientId ) ) { return LockResult . HOLD_BY_ANOTHER_CLIENT ; } } if ( ! StringUtils . isBlank ( getClientId ( ) ) && getTimestampExpiry ( ) >= System . currentTimeMillis ( ) && ! StringUtils . equals ( getClientId ( ) , clientId ) ) { return LockResult . HOLD_BY_ANOTHER_CLIENT ; } updateLockHolder ( clientId , lockDurationMs ) ; if ( waitWeight >= 0 ) { synchronized ( pQueue ) { pQueue . clear ( ) ; } } return LockResult . SUCCESSFUL ; } catch ( Exception e ) { throw e instanceof DLockException ? ( DLockException ) e : new DLockException ( e ) ; } } }
{@inheritDoc}