Search in sources :

Example 91 with ClientInvocation

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

the class SessionlessSemaphoreProxy method doTryAcquire.

private boolean doTryAcquire(int permits, long timeoutMs) {
    long clusterWideThreadId = sessionManager.getOrCreateUniqueThreadId(groupId);
    UUID invocationUid = newUnsecureUUID();
    ClientMessage request = SemaphoreAcquireCodec.encodeRequest(groupId, objectName, NO_SESSION_ID, clusterWideThreadId, invocationUid, permits, timeoutMs);
    try {
        ClientMessage response = new ClientInvocation(getClient(), request, objectName).invoke().joinInternal();
        return SemaphoreAcquireCodec.decodeResponse(response);
    } catch (WaitKeyCancelledException e) {
        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.");
    }
}
Also used : WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 92 with ClientInvocation

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

the class SessionlessSemaphoreProxy method doChangePermits.

private void doChangePermits(int delta) {
    long clusterWideThreadId = sessionManager.getOrCreateUniqueThreadId(groupId);
    UUID invocationUid = newUnsecureUUID();
    ClientMessage request = SemaphoreChangeCodec.encodeRequest(groupId, objectName, NO_SESSION_ID, clusterWideThreadId, invocationUid, delta);
    new ClientInvocation(getClient(), request, objectName).invoke().joinInternal();
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 93 with ClientInvocation

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

the class SessionlessSemaphoreProxy method release.

@Override
public void release(int permits) {
    checkPositive(permits, "Permits must be positive!");
    long clusterWideThreadId = sessionManager.getOrCreateUniqueThreadId(groupId);
    UUID invocationUid = newUnsecureUUID();
    ClientMessage request = SemaphoreReleaseCodec.encodeRequest(groupId, objectName, NO_SESSION_ID, clusterWideThreadId, invocationUid, permits);
    HazelcastClientInstanceImpl client = getClient();
    new ClientInvocation(client, request, objectName).invoke().joinInternal();
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID)

Example 94 with ClientInvocation

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

the class HazelcastClientInstanceImpl method getDistributedObjects.

@Override
public Collection<DistributedObject> getDistributedObjects() {
    try {
        ClientMessage request = ClientGetDistributedObjectsCodec.encodeRequest();
        final Future<ClientMessage> future = new ClientInvocation(this, request, getName()).invoke();
        ClientMessage response = future.get();
        Collection<? extends DistributedObject> distributedObjects = proxyManager.getDistributedObjects();
        Set<DistributedObjectInfo> localDistributedObjects = new HashSet<>();
        for (DistributedObject localInfo : distributedObjects) {
            localDistributedObjects.add(new DistributedObjectInfo(localInfo.getServiceName(), localInfo.getName()));
        }
        for (DistributedObjectInfo distributedObjectInfo : ClientGetDistributedObjectsCodec.decodeResponse(response)) {
            localDistributedObjects.remove(distributedObjectInfo);
            getDistributedObject(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName(), false);
        }
        for (DistributedObjectInfo distributedObjectInfo : localDistributedObjects) {
            proxyManager.destroyProxyLocally(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName());
        }
        return (Collection<DistributedObject>) proxyManager.getDistributedObjects();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) DistributedObjectInfo(com.hazelcast.client.impl.client.DistributedObjectInfo) Collection(java.util.Collection) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ExecutionException(java.util.concurrent.ExecutionException) TransactionException(com.hazelcast.transaction.TransactionException) HashSet(java.util.HashSet)

Example 95 with ClientInvocation

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

the class ClientDynamicClusterConfig method invoke.

private void invoke(ClientMessage request) {
    try {
        ClientInvocation invocation = new ClientInvocation(instance, request, null);
        ClientInvocationFuture future = invocation.invoke();
        future.get();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) 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