Search in sources :

Example 16 with RaftOp

use of com.hazelcast.cp.internal.RaftOp in project hazelcast by hazelcast.

the class AddAndGetMessageTask method processMessage.

@Override
protected void processMessage() {
    CPGroupId groupId = parameters.groupId;
    long delta = parameters.delta;
    RaftOp op = new AddAndGetOp(parameters.name, delta);
    if (delta == 0) {
        query(groupId, op, LINEARIZABLE);
    } else {
        invoke(groupId, op);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) AddAndGetOp(com.hazelcast.cp.internal.datastructures.atomiclong.operation.AddAndGetOp) RaftOp(com.hazelcast.cp.internal.RaftOp)

Example 17 with RaftOp

use of com.hazelcast.cp.internal.RaftOp in project hazelcast by hazelcast.

the class ApplyMessageTask method processMessage.

@Override
protected void processMessage() {
    ReturnValueType returnValueType = ReturnValueType.fromValue(parameters.returnValueType);
    CPGroupId groupId = parameters.groupId;
    RaftOp op = new ApplyOp(parameters.name, parameters.function, returnValueType, parameters.alter);
    if (parameters.alter) {
        invoke(groupId, op);
    } else {
        query(groupId, op, LINEARIZABLE);
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) ReturnValueType(com.hazelcast.cp.internal.datastructures.atomicref.operation.ApplyOp.ReturnValueType) RaftOp(com.hazelcast.cp.internal.RaftOp) ApplyOp(com.hazelcast.cp.internal.datastructures.atomicref.operation.ApplyOp)

Example 18 with RaftOp

use of com.hazelcast.cp.internal.RaftOp 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 19 with RaftOp

use of com.hazelcast.cp.internal.RaftOp 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;
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) AcquirePermitsOp(com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp) 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 20 with RaftOp

use of com.hazelcast.cp.internal.RaftOp 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)

Aggregations

RaftOp (com.hazelcast.cp.internal.RaftOp)28 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)7 UUID (java.util.UUID)7 AcquirePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.AcquirePermitsOp)6 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)5 CPGroupId (com.hazelcast.cp.CPGroupId)4 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)4 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)4 ChangePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ChangePermitsOp)4 ReleasePermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.ReleasePermitsOp)4 DrainPermitsOp (com.hazelcast.cp.internal.datastructures.semaphore.operation.DrainPermitsOp)3 Test (org.junit.Test)3 RaftService (com.hazelcast.cp.internal.RaftService)2 ApplyOp (com.hazelcast.cp.internal.datastructures.atomicref.operation.ApplyOp)2 TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)2 ExpireWaitKeysOp (com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp)2 AbstractProxySessionManager (com.hazelcast.cp.internal.session.AbstractProxySessionManager)2 BiTuple (com.hazelcast.internal.util.BiTuple)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)2