Search in sources :

Example 1 with ReleasePermitsOp

use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.

the class AbstractSemaphoreAdvancedTest method testRetriedReleaseIsSuccessfulAfterAcquiredByAnotherEndpoint.

@Test
public void testRetriedReleaseIsSuccessfulAfterAcquiredByAnotherEndpoint() throws InterruptedException {
    semaphore.init(1);
    semaphore.acquire();
    RaftGroupId groupId = getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    UUID invUid = newUnsecureUUID();
    invokeRaftOp(groupId, new ReleasePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
    spawn(() -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    invokeRaftOp(groupId, new ReleasePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
}
Also used : ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with ReleasePermitsOp

use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp 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 3 with ReleasePermitsOp

use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.

the class ReleasePermitsMessageTask method processMessage.

@Override
protected void processMessage() {
    RaftOp op = new ReleasePermitsOp(parameters.name, parameters.sessionId, parameters.threadId, parameters.invocationUid, parameters.permits);
    invoke(parameters.groupId, op);
}
Also used : ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp)

Example 4 with ReleasePermitsOp

use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.

the class SessionlessSemaphoreProxy method release.

@Override
public void release(int permits) {
    checkPositive(permits, "Permits must be positive!");
    long clusterWideThreadId = getOrCreateUniqueThreadId();
    RaftOp op = new ReleasePermitsOp(objectName, NO_SESSION_ID, clusterWideThreadId, newUnsecureUUID(), permits);
    invocationManager.invoke(groupId, op).joinInternal();
}
Also used : ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp)

Example 5 with ReleasePermitsOp

use of com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp in project hazelcast by hazelcast.

the class AbstractSemaphoreAdvancedTest method testInactiveSessionsAreEventuallyClosed.

@Test
public void testInactiveSessionsAreEventuallyClosed() throws ExecutionException, InterruptedException {
    semaphore.init(1);
    semaphore.acquire();
    RaftGroupId groupId = getGroupId();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService sessionService = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertFalse(sessionService.getAllSessions(groupId).get().isEmpty());
        }
    });
    AbstractProxySessionManager sessionManager = getSessionManager();
    long sessionId = sessionManager.getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    // Not using semaphore.release(), because we want to keep sending session HBs.
    RaftOp op = new ReleasePermitsOp(objectName, sessionId, getThreadId(), newUnsecureUUID(), 1);
    invokeRaftOp(groupId, op).get();
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftSessionService service1 = getNodeEngineImpl(instance).getService(RaftSessionService.SERVICE_NAME);
            assertTrue(service1.getAllSessions(groupId).get().isEmpty());
        }
        assertEquals(NO_SESSION_ID, sessionManager.getSession(groupId));
    });
}
Also used : RaftSessionService(com.hazelcast.cp.internal.session.RaftSessionService) ReleasePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) RaftOp(com.hazelcast.cp.internal.RaftOp) Test(org.junit.Test)

Aggregations

ReleasePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp)5 RaftOp (com.hazelcast.cp.internal.RaftOp)4 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)2 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)1 RaftSessionService (com.hazelcast.cp.internal.session.RaftSessionService)1 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)1