Search in sources :

Example 1 with DrainPermitsOp

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();
}
Also used : RaftOp(com.hazelcast.cp.internal.RaftOp) DrainPermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp)

Example 2 with DrainPermitsOp

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());
}
Also used : RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) DrainPermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp) Test(org.junit.Test)

Example 3 with DrainPermitsOp

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;
        }
    }
}
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 4 with DrainPermitsOp

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);
}
Also used : RaftOp(com.hazelcast.cp.internal.RaftOp) DrainPermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp)

Example 5 with DrainPermitsOp

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());
}
Also used : RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) DrainPermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp) Test(org.junit.Test)

Aggregations

DrainPermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp)5 RaftOp (com.hazelcast.cp.internal.RaftOp)3 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)3 UUID (java.util.UUID)3 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)2 Test (org.junit.Test)2 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)1 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)1