Search in sources :

Example 31 with ClientInvocation

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

the class SessionAwareSemaphoreProxy method release.

@Override
public void release(int permits) {
    checkPositive(permits, "Permits must be positive!");
    long sessionId = sessionManager.getSession(groupId);
    if (sessionId == NO_SESSION_ID) {
        throw newIllegalStateException(null);
    }
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    try {
        ClientMessage request = SemaphoreReleaseCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, permits);
        HazelcastClientInstanceImpl client = getClient();
        new ClientInvocation(client, request, objectName).invoke().joinInternal();
    } catch (SessionExpiredException e) {
        sessionManager.invalidateSession(this.groupId, sessionId);
        throw newIllegalStateException(e);
    } finally {
        sessionManager.releaseSession(this.groupId, sessionId, permits);
    }
}
Also used : 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 32 with ClientInvocation

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

the class SessionAwareSemaphoreProxy method doChangePermits.

private void doChangePermits(int delta) {
    long sessionId = sessionManager.acquireSession(groupId);
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    try {
        ClientMessage request = SemaphoreChangeCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid, delta);
        new ClientInvocation(getClient(), request, objectName).invoke().joinInternal();
    } catch (SessionExpiredException e) {
        sessionManager.invalidateSession(this.groupId, sessionId);
        throw newIllegalStateException(e);
    } finally {
        sessionManager.releaseSession(this.groupId, sessionId);
    }
}
Also used : 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 33 with ClientInvocation

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

the class SessionAwareSemaphoreProxy method init.

@Override
public boolean init(int permits) {
    checkNotNegative(permits, "Permits must be non-negative!");
    ClientMessage request = SemaphoreInitCodec.encodeRequest(groupId, objectName, permits);
    HazelcastClientInstanceImpl client = getClient();
    ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
    return SemaphoreInitCodec.decodeResponse(response);
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 34 with ClientInvocation

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

the class SessionAwareSemaphoreProxy method drainPermits.

@Override
public int drainPermits() {
    long threadId = getThreadId();
    UUID invocationUid = newUnsecureUUID();
    for (; ; ) {
        long sessionId = sessionManager.acquireSession(this.groupId, DRAIN_SESSION_ACQ_COUNT);
        try {
            ClientMessage request = SemaphoreDrainCodec.encodeRequest(groupId, objectName, sessionId, threadId, invocationUid);
            HazelcastClientInstanceImpl client = getClient();
            ClientMessage response = new ClientInvocation(client, request, objectName).invoke().joinInternal();
            int count = SemaphoreDrainCodec.decodeResponse(response);
            sessionManager.releaseSession(groupId, sessionId, DRAIN_SESSION_ACQ_COUNT - count);
            return count;
        } catch (SessionExpiredException e) {
            sessionManager.invalidateSession(this.groupId, sessionId);
        } catch (RuntimeException e) {
            sessionManager.releaseSession(this.groupId, sessionId, DRAIN_SESSION_ACQ_COUNT);
            throw e;
        }
    }
}
Also used : 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 35 with ClientInvocation

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

the class ClientMapQueryPartitionIterator method fetch.

@Override
protected List<Data> fetch() {
    HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
    ClientMessage request = MapFetchWithQueryCodec.encodeRequest(mapProxy.getName(), encodePointers(pointers), fetchSize, getSerializationService().toData(query.getProjection()), getSerializationService().toData(query.getPredicate()));
    ClientInvocation clientInvocation = new ClientInvocation(client, request, mapProxy.getName(), partitionId);
    try {
        ClientInvocationFuture f = clientInvocation.invoke();
        MapFetchWithQueryCodec.ResponseParameters responseParameters = MapFetchWithQueryCodec.decodeResponse(f.get());
        List<Data> results = responseParameters.results;
        IterationPointer[] pointers = decodePointers(responseParameters.iterationPointers);
        setLastTableIndex(results, pointers);
        return results;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : IterationPointer(com.hazelcast.internal.iteration.IterationPointer) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapFetchWithQueryCodec(com.hazelcast.client.impl.protocol.codec.MapFetchWithQueryCodec) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

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