use of com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp in project hazelcast by hazelcast.
the class SessionlessSemaphoreProxy method drainPermits.
@Override
public int drainPermits() {
long clusterWideThreadId = getOrCreateUniqueThreadId();
RaftOp op = new DrainPermitsOp(objectName, NO_SESSION_ID, clusterWideThreadId, newUnsecureUUID());
return invocationManager.<Integer>invoke(groupId, op).joinInternal();
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testRetriedDrainRequestIsNotProcessedAgain.
@Test(timeout = 300_000)
public void testRetriedDrainRequestIsNotProcessedAgain() throws InterruptedException, ExecutionException {
assumeFalse(isJDKCompatible());
semaphore.init(1);
semaphore.acquire();
final RaftGroupId groupId = getGroupId(semaphore);
long sessionId = getSessionId(proxyInstance, groupId);
long threadId = getThreadId(groupId);
UUID invUid = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Integer> f1 = invocationManager.invoke(groupId, new DrainPermitsOp(objectName, sessionId, threadId, invUid));
assertEquals(0, (int) f1.joinInternal());
spawn(() -> semaphore.release()).get();
InternalCompletableFuture<Integer> f2 = invocationManager.invoke(groupId, new DrainPermitsOp(objectName, sessionId, threadId, invUid));
assertEquals(0, (int) f2.joinInternal());
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp 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.datastructures.semaphore.operation.DrainPermitsOp in project hazelcast by hazelcast.
the class DrainPermitsMessageTask method processMessage.
@Override
protected void processMessage() {
RaftOp op = new DrainPermitsOp(parameters.name, parameters.sessionId, parameters.threadId, parameters.invocationUid);
invoke(parameters.groupId, op);
}
use of com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testRetriedDrainPermitsAppliedOnlyOnce.
@Test
public void testRetriedDrainPermitsAppliedOnlyOnce() throws ExecutionException, InterruptedException {
semaphore.increasePermits(3);
RaftGroupId groupId = getGroupId();
long sessionId = getSessionManager().getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
UUID invUid = newUnsecureUUID();
int drained1 = this.<Integer>invokeRaftOp(groupId, new DrainPermitsOp(objectName, sessionId, getThreadId(), invUid)).joinInternal();
assertEquals(3, drained1);
assertEquals(0, semaphore.availablePermits());
spawn(() -> semaphore.increasePermits(1)).get();
int drained2 = this.<Integer>invokeRaftOp(groupId, new DrainPermitsOp(objectName, sessionId, getThreadId(), invUid)).joinInternal();
assertEquals(3, drained2);
assertEquals(1, semaphore.availablePermits());
}
Aggregations