Search in sources :

Example 1 with LockAcquireLimitReachedException

use of com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException in project hazelcast by hazelcast.

the class AbstractFencedLockProxy method lockInterruptibly.

@Override
public void lockInterruptibly() throws InterruptedException {
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = acquireSession();
        verifyLockedSessionIdIfPresent(threadId, sessionId, true);
        try {
            long fence = doLock(sessionId, threadId, invocationUid).get();
            if (fence != INVALID_FENCE) {
                lockedSessionIds.put(threadId, sessionId);
                return;
            }
            throw new LockAcquireLimitReachedException("Lock[" + objectName + "] reentrant lock limit is already reached!");
        } catch (SessionExpiredException e) {
            invalidateSession(sessionId);
            verifyNoLockedSessionIdPresent(threadId);
        } catch (WaitKeyCancelledException e) {
            releaseSession(sessionId);
            throw new IllegalMonitorStateException("Lock[" + objectName + "] not acquired because the lock call " + "on the CP group is cancelled, possibly because of another indeterminate call from the same thread.");
        } catch (Throwable t) {
            releaseSession(sessionId);
            if (t instanceof InterruptedException) {
                throw (InterruptedException) t;
            } else {
                throw rethrow(t);
            }
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) LockAcquireLimitReachedException(com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException)

Example 2 with LockAcquireLimitReachedException

use of com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException in project hazelcast by hazelcast.

the class AbstractFencedLockProxy method lockAndGetFence.

@Override
public final long lockAndGetFence() {
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = acquireSession();
        verifyLockedSessionIdIfPresent(threadId, sessionId, true);
        try {
            long fence = doLock(sessionId, threadId, invocationUid).joinInternal();
            if (fence != INVALID_FENCE) {
                lockedSessionIds.put(threadId, sessionId);
                return fence;
            }
            throw new LockAcquireLimitReachedException("Lock[" + objectName + "] reentrant lock limit is already reached!");
        } catch (SessionExpiredException e) {
            invalidateSession(sessionId);
            verifyNoLockedSessionIdPresent(threadId);
        } catch (WaitKeyCancelledException e) {
            releaseSession(sessionId);
            throw new IllegalMonitorStateException("Lock[" + objectName + "] not acquired because the lock call " + "on the CP group is cancelled, possibly because of another indeterminate call from the same thread.");
        } catch (Throwable t) {
            releaseSession(sessionId);
            throw rethrow(t);
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) LockAcquireLimitReachedException(com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException)

Aggregations

WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)2 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)2 LockAcquireLimitReachedException (com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException)2 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)2 UUID (java.util.UUID)2