Search in sources :

Example 1 with ChangePermitsOp

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

the class SessionlessSemaphoreProxy method increasePermits.

@Override
public void increasePermits(int increase) {
    checkNotNegative(increase, "Increase must be non-negative!");
    if (increase == 0) {
        return;
    }
    long clusterWideThreadId = getOrCreateUniqueThreadId();
    RaftOp op = new ChangePermitsOp(objectName, NO_SESSION_ID, clusterWideThreadId, newUnsecureUUID(), increase);
    invocationManager.invoke(groupId, op).joinInternal();
}
Also used : ChangePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp)

Example 2 with ChangePermitsOp

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

the class SessionlessSemaphoreProxy method reducePermits.

@Override
public void reducePermits(int reduction) {
    checkNotNegative(reduction, "Reduction must be non-negative!");
    if (reduction == 0) {
        return;
    }
    long clusterWideThreadId = getOrCreateUniqueThreadId();
    RaftOp op = new ChangePermitsOp(objectName, NO_SESSION_ID, clusterWideThreadId, newUnsecureUUID(), -reduction);
    invocationManager.invoke(groupId, op).joinInternal();
}
Also used : ChangePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp) RaftOp(com.hazelcast.cp.internal.RaftOp)

Example 3 with ChangePermitsOp

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

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

the class ChangePermitsMessageTask method processMessage.

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

Example 5 with ChangePermitsOp

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

the class AbstractSemaphoreAdvancedTest method testRetriedIncreasePermitsAppliedOnlyOnce.

@Test
public void testRetriedIncreasePermitsAppliedOnlyOnce() throws InterruptedException {
    semaphore.init(1);
    semaphore.acquire();
    semaphore.release();
    // we guarantee that there is a session id now...
    RaftGroupId groupId = getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    UUID invUid = newUnsecureUUID();
    invokeRaftOp(groupId, new ChangePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
    invokeRaftOp(groupId, new ChangePermitsOp(objectName, sessionId, getThreadId(), invUid, 1)).joinInternal();
    assertEquals(2, semaphore.availablePermits());
}
Also used : ChangePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ChangePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp)6 RaftOp (com.hazelcast.cp.internal.RaftOp)4 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 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)1