Search in sources :

Example 11 with RaftOp

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

the class UnlockMessageTask method processMessage.

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

Example 12 with RaftOp

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

the class SessionAwareSemaphoreProxy method tryAcquire.

@Override
public boolean tryAcquire(int permits, long timeout, TimeUnit unit) {
    checkPositive("permits", permits);
    long timeoutMs = max(0, unit.toMillis(timeout));
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    long start;
    for (; ; ) {
        start = Clock.currentTimeMillis();
        long sessionId = acquireSession(permits);
        RaftOp op = new AcquirePermitsOp(objectName, sessionId, threadId, invocationUid, permits, timeoutMs);
        try {
            InternalCompletableFuture<Boolean> f = invocationManager.invoke(groupId, op);
            boolean acquired = f.joinInternal();
            if (!acquired) {
                releaseSession(sessionId, permits);
            }
            return acquired;
        } catch (SessionExpiredException e) {
            invalidateSession(sessionId);
            timeoutMs -= (Clock.currentTimeMillis() - start);
            if (timeoutMs <= 0) {
                return false;
            }
        } catch (WaitKeyCancelledException e) {
            releaseSession(sessionId, permits);
            return false;
        } 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 13 with RaftOp

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

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

the class AcquirePermitsMessageTask method processMessage.

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

Example 15 with RaftOp

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

the class TryLockMessageTask method processMessage.

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

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