Search in sources :

Example 6 with SessionExpiredException

use of com.hazelcast.cp.internal.session.SessionExpiredException in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method doChangePermits.

private void doChangePermits(int delta) {
    long sessionId = acquireSession();
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    try {
        RaftOp op = new ChangePermitsOp(objectName, sessionId, threadId, invocationUid, delta);
        invocationManager.invoke(groupId, op).joinInternal();
    } catch (SessionExpiredException e) {
        invalidateSession(sessionId);
        throw newIllegalStateException(e);
    } finally {
        releaseSession(sessionId);
    }
}
Also used : ChangePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 7 with SessionExpiredException

use of com.hazelcast.cp.internal.session.SessionExpiredException in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method drainPermits.

@Override
public int drainPermits() {
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = acquireSession(DRAIN_SESSION_ACQ_COUNT);
        RaftOp op = new DrainPermitsOp(objectName, sessionId, threadId, invocationUid);
        try {
            InternalCompletableFuture<Integer> future = invocationManager.invoke(groupId, op);
            int count = future.joinInternal();
            releaseSession(sessionId, DRAIN_SESSION_ACQ_COUNT - count);
            return count;
        } catch (SessionExpiredException e) {
            invalidateSession(sessionId);
        } catch (RuntimeException e) {
            releaseSession(sessionId, DRAIN_SESSION_ACQ_COUNT);
            throw e;
        }
    }
}
Also used : RaftOp(com.hazelcast.cp.internal.RaftOp) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) DrainPermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp)

Example 8 with SessionExpiredException

use of com.hazelcast.cp.internal.session.SessionExpiredException in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method acquire.

@Override
public void acquire(int permits) {
    checkPositive(permits, "Permits must be positive!");
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = acquireSession(permits);
        RaftOp op = new AcquirePermitsOp(objectName, sessionId, threadId, invocationUid, permits, -1L);
        try {
            invocationManager.invoke(groupId, op).joinInternal();
            return;
        } catch (SessionExpiredException e) {
            invalidateSession(sessionId);
        } catch (WaitKeyCancelledException e) {
            releaseSession(sessionId, permits);
            throw new IllegalStateException("Semaphore[" + objectName + "] not acquired because the acquire call " + "on the CP group is cancelled, possibly because of another indeterminate call from the same thread.");
        } catch (RuntimeException e) {
            releaseSession(sessionId, permits);
            throw e;
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) AcquirePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 9 with SessionExpiredException

use of com.hazelcast.cp.internal.session.SessionExpiredException in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method release.

@Override
public void release(int permits) {
    checkPositive(permits, "Permits must be positive!");
    long sessionId = getSession();
    if (sessionId == NO_SESSION_ID) {
        throw newIllegalStateException(null);
    }
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    RaftOp op = new ReleasePermitsOp(objectName, sessionId, threadId, invocationUid, permits);
    try {
        invocationManager.invoke(groupId, op).joinInternal();
    } catch (SessionExpiredException e) {
        invalidateSession(sessionId);
        throw newIllegalStateException(e);
    } finally {
        releaseSession(sessionId, permits);
    }
}
Also used : ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 10 with SessionExpiredException

use of com.hazelcast.cp.internal.session.SessionExpiredException 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

SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)14 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)13 UUID (java.util.UUID)13 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)7 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)5 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)5 RaftOp (com.hazelcast.cp.internal.RaftOp)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)2 LockAcquireLimitReachedException (com.hazelcast.cp.lock.exception.LockAcquireLimitReachedException)2 ChangePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp)1 DrainPermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp)1 ReleasePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp)1 Long2ObjectHashMap (com.hazelcast.internal.util.collection.Long2ObjectHashMap)1 ArrayList (java.util.ArrayList)1