Search in sources :

Example 71 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method onDestroy.

@Override
public void onDestroy() {
    ClientMessage request = CPGroupDestroyCPObjectCodec.encodeRequest(groupId, getServiceName(), objectName);
    new ClientInvocation(getClient(), request, name).invoke().joinInternal();
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 72 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method tryAcquire.

@Override
public boolean tryAcquire(int permits, long timeout, TimeUnit unit) {
    checkPositive(permits, "Permits must be positive!");
    long timeoutMs = max(0, unit.toMillis(timeout));
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    long start;
    for (; ; ) {
        start = Clock.currentTimeMillis();
        long sessionId = sessionManager.acquireSession(this.groupId, permits);
        try {
            ClientMessage request = SemaphoreAcquireCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, permits, timeoutMs);
            HazelcastClientInstanceImpl client = getClient();
            ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
            boolean acquired = SemaphoreAcquireCodec.decodeResponse(response);
            if (!acquired) {
                sessionManager.releaseSession(this.groupId, sessionId, permits);
            }
            return acquired;
        } catch (SessionExpiredException e) {
            sessionManager.invalidateSession(this.groupId, sessionId);
            timeoutMs -= (Clock.currentTimeMillis() - start);
            if (timeoutMs <= 0) {
                return false;
            }
        } catch (WaitKeyCancelledException e) {
            sessionManager.releaseSession(this.groupId, sessionId, permits);
            return false;
        } catch (RuntimeException e) {
            sessionManager.releaseSession(this.groupId, sessionId, permits);
            throw e;
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 73 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class SessionAwareSemaphoreProxy method acquire.

@Override
public void acquire(int permits) {
    checkPositive("permits", permits);
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = sessionManager.acquireSession(this.groupId, permits);
        try {
            ClientMessage request = SemaphoreAcquireCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, permits, -1);
            HazelcastClientInstanceImpl client = getClient();
            new ClientInvocation(client, request, objectName).invoke().joinInternal();
            return;
        } catch (SessionExpiredException e) {
            sessionManager.invalidateSession(this.groupId, sessionId);
        } catch (WaitKeyCancelledException e) {
            sessionManager.releaseSession(this.groupId, 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) {
            sessionManager.releaseSession(this.groupId, sessionId, permits);
            throw e;
        }
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) SessionExpiredException(com.hazelcast.cp.internal.session.SessionExpiredException) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 74 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class AtomicLongProxy method addAndGetAsync.

@Override
public InternalCompletableFuture<Long> addAndGetAsync(long delta) {
    ClientMessage request = AtomicLongAddAndGetCodec.encodeRequest(groupId, objectName, delta);
    ClientInvocationFuture future = new ClientInvocation(getClient(), request, name).invoke();
    return new ClientDelegatingFuture<>(future, getSerializationService(), AtomicLongAddAndGetCodec::decodeResponse);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) AtomicLongAddAndGetCodec(com.hazelcast.client.impl.protocol.codec.AtomicLongAddAndGetCodec) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 75 with ClientInvocation

use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.

the class AtomicLongProxy method onDestroy.

@Override
public void onDestroy() {
    ClientMessage request = CPGroupDestroyCPObjectCodec.encodeRequest(groupId, getServiceName(), objectName);
    new ClientInvocation(getClient(), request, name).invoke().joinInternal();
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Aggregations

ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)129 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)97 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)54 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)51 Test (org.junit.Test)23 Data (com.hazelcast.internal.serialization.Data)22 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 UUID (java.util.UUID)18 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)16 Future (java.util.concurrent.Future)13 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)9 ArrayList (java.util.ArrayList)9 Nonnull (javax.annotation.Nonnull)9 ExecutionException (java.util.concurrent.ExecutionException)8 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)7 Collection (java.util.Collection)6 List (java.util.List)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6