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);
}
}
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;
}
}
}
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;
}
}
}
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);
}
}
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);
}
}
}
Aggregations