Search in sources :

Example 61 with ClientInvocationFuture

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

the class ClientScheduledFutureProxy method get0.

private V get0(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
    checkAccessibleHandler();
    UUID uuid = handler.getUuid();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    if (uuid != null) {
        ClientMessage request = ScheduledExecutorGetResultFromMemberCodec.encodeRequest(schedulerName, taskName, uuid);
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, schedulerName, uuid).invoke();
        ClientMessage response = future.get(timeout, unit);
        Data data = ScheduledExecutorGetResultFromMemberCodec.decodeResponse(response);
        return toObject(data);
    } else {
        ClientMessage request = ScheduledExecutorGetResultFromPartitionCodec.encodeRequest(schedulerName, taskName);
        ClientInvocationFuture future = new ClientInvocation(getClient(), request, schedulerName, partitionId).invoke();
        ClientMessage response = future.get(timeout, unit);
        Data data = ScheduledExecutorGetResultFromPartitionCodec.decodeResponse(response);
        return toObject(data);
    }
}
Also used : ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 62 with ClientInvocationFuture

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

the class ClientMapProxy method submitToKeyInternal.

public <R> InternalCompletableFuture<R> submitToKeyInternal(Object key, EntryProcessor<K, V, R> entryProcessor) {
    try {
        Data keyData = toData(key);
        ClientMessage request = MapSubmitToKeyCodec.encodeRequest(name, toData(entryProcessor), keyData, getThreadId());
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        SerializationService ss = getSerializationService();
        return new ClientDelegatingFuture(future, ss, MapSubmitToKeyCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) MapSubmitToKeyCodec(com.hazelcast.client.impl.protocol.codec.MapSubmitToKeyCodec)

Example 63 with ClientInvocationFuture

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

the class ClientListenerServiceImpl method invoke.

protected void invoke(ClientListenerRegistration listenerRegistration, Connection connection) throws Exception {
    // This method should only be called from registrationExecutor
    assert (Thread.currentThread().getName().contains("eventRegistration"));
    if (listenerRegistration.getConnectionRegistrations().containsKey(connection)) {
        return;
    }
    ListenerMessageCodec codec = listenerRegistration.getCodec();
    ClientMessage request = codec.encodeAddRequest(registersLocalOnly());
    EventHandler handler = listenerRegistration.getHandler();
    if (logger.isFinestEnabled()) {
        logger.finest("Register attempt of " + listenerRegistration + " to " + connection);
    }
    handler.beforeListenerRegister(connection);
    ClientInvocation invocation = new ClientInvocation(client, request, null, connection);
    invocation.setEventHandler(handler);
    ClientInvocationFuture future = invocation.invokeUrgent();
    ClientMessage clientMessage;
    try {
        clientMessage = future.get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e, Exception.class);
    }
    UUID serverRegistrationId = codec.decodeAddResponse(clientMessage);
    if (logger.isFinestEnabled()) {
        logger.finest("Registered " + listenerRegistration + " to " + connection);
    }
    handler.onListenerRegister(connection);
    long correlationId = request.getCorrelationId();
    ClientConnectionRegistration registration = new ClientConnectionRegistration(serverRegistrationId, correlationId);
    listenerRegistration.getConnectionRegistrations().put(connection, registration);
}
Also used : ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) EventHandler(com.hazelcast.client.impl.spi.EventHandler) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 64 with ClientInvocationFuture

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

the class NearCachedClientMapProxy method getAsync.

@Override
public InternalCompletableFuture<V> getAsync(@Nonnull K key) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
    final Object ncKey = toNearCacheKey(key);
    Object value = getCachedValue(ncKey, false);
    if (value != NOT_CACHED) {
        return newCompletedFuture(value, getSerializationService());
    }
    Data keyData = toData(ncKey);
    final long reservationId = nearCache.tryReserveForUpdate(ncKey, keyData, READ_UPDATE);
    ClientInvocationFuture invocationFuture;
    try {
        invocationFuture = super.getAsyncInternal(keyData);
    } catch (Throwable t) {
        invalidateNearCache(ncKey);
        throw rethrow(t);
    }
    if (reservationId != NOT_RESERVED) {
        invocationFuture.whenCompleteAsync((response, t) -> {
            if (t == null) {
                Object newDecodedResponse = MapGetCodec.decodeResponse(response);
                nearCache.tryPublishReserved(ncKey, newDecodedResponse, reservationId, false);
            } else {
                invalidateNearCache(ncKey);
            }
        }, getClient().getTaskScheduler());
    }
    return new ClientDelegatingFuture<>(getAsyncInternal(key), getSerializationService(), MapGetCodec::decodeResponse);
}
Also used : MapGetCodec(com.hazelcast.client.impl.protocol.codec.MapGetCodec) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Data(com.hazelcast.internal.serialization.Data) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 65 with ClientInvocationFuture

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

the class ClientMapPartitionIterator method fetchWithoutPrefetchValues.

private List fetchWithoutPrefetchValues(HazelcastClientInstanceImpl client) {
    ClientMessage request = MapFetchKeysCodec.encodeRequest(mapProxy.getName(), encodePointers(pointers), fetchSize);
    ClientInvocation clientInvocation = new ClientInvocation(client, request, mapProxy.getName(), partitionId);
    try {
        ClientInvocationFuture f = clientInvocation.invoke();
        MapFetchKeysCodec.ResponseParameters responseParameters = MapFetchKeysCodec.decodeResponse(f.get());
        IterationPointer[] pointers = decodePointers(responseParameters.iterationPointers);
        setIterationPointers(responseParameters.keys, pointers);
        return responseParameters.keys;
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : IterationPointer(com.hazelcast.internal.iteration.IterationPointer) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) MapFetchKeysCodec(com.hazelcast.client.impl.protocol.codec.MapFetchKeysCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)65 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)54 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)44 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)34 Data (com.hazelcast.internal.serialization.Data)22 UUID (java.util.UUID)11 Nonnull (javax.annotation.Nonnull)6 ILogger (com.hazelcast.logging.ILogger)5 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 IterationPointer (com.hazelcast.internal.iteration.IterationPointer)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)4 CachePutCodec (com.hazelcast.client.impl.protocol.codec.CachePutCodec)3 DurableExecutorRetrieveResultCodec (com.hazelcast.client.impl.protocol.codec.DurableExecutorRetrieveResultCodec)3 Member (com.hazelcast.cluster.Member)3 ExecutionCallbackAdapter (com.hazelcast.executor.impl.ExecutionCallbackAdapter)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 AccessControlException (java.security.AccessControlException)3 List (java.util.List)3