Search in sources :

Example 26 with ClientDelegatingFuture

use of com.hazelcast.client.impl.ClientDelegatingFuture in project hazelcast by hazelcast.

the class ClientMapProxy method setAsyncInternal.

protected InternalCompletableFuture<Void> setAsyncInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
    try {
        Data keyData = toData(key);
        Data valueData = toData(value);
        long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
        ClientMessage request;
        if (maxIdle != null) {
            request = MapSetWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
        } else {
            request = MapSetCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
        }
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        return new ClientDelegatingFuture<>(future, getSerializationService(), clientMessage -> null);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) Data(com.hazelcast.internal.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 27 with ClientDelegatingFuture

use of com.hazelcast.client.impl.ClientDelegatingFuture in project hazelcast by hazelcast.

the class ClientMapProxy method putAsyncInternal.

protected InternalCompletableFuture<V> putAsyncInternal(long ttl, TimeUnit timeunit, Long maxIdle, TimeUnit maxIdleUnit, Object key, Object value) {
    try {
        Data keyData = toData(key);
        Data valueData = toData(value);
        long ttlMillis = timeInMsOrOneIfResultIsZero(ttl, timeunit);
        ClientMessage request;
        if (maxIdle != null) {
            request = MapPutWithMaxIdleCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis, timeInMsOrOneIfResultIsZero(maxIdle, maxIdleUnit));
        } else {
            request = MapPutCodec.encodeRequest(name, keyData, valueData, getThreadId(), ttlMillis);
        }
        ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
        SerializationService ss = getSerializationService();
        return new ClientDelegatingFuture<>(future, ss, MapPutCodec::decodeResponse);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) MapPutCodec(com.hazelcast.client.impl.protocol.codec.MapPutCodec) 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)

Example 28 with ClientDelegatingFuture

use of com.hazelcast.client.impl.ClientDelegatingFuture 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 29 with ClientDelegatingFuture

use of com.hazelcast.client.impl.ClientDelegatingFuture 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 30 with ClientDelegatingFuture

use of com.hazelcast.client.impl.ClientDelegatingFuture in project hazelcast by hazelcast.

the class ClientCacheProxy method subscribeToEventJournal.

@Override
public InternalCompletableFuture<EventJournalInitialSubscriberState> subscribeToEventJournal(int partitionId) {
    final ClientMessage request = CacheEventJournalSubscribeCodec.encodeRequest(nameWithPrefix);
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, getSerializationService(), eventJournalSubscribeResponseDecoder);
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)54 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)46 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)32 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)31 Test (org.junit.Test)17 Data (com.hazelcast.internal.serialization.Data)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 SerializationService (com.hazelcast.internal.serialization.SerializationService)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 Nonnull (javax.annotation.Nonnull)3 AtomicLongAlterCodec (com.hazelcast.client.impl.protocol.codec.AtomicLongAlterCodec)2 AtomicRefSetCodec (com.hazelcast.client.impl.protocol.codec.AtomicRefSetCodec)2 MapGetCodec (com.hazelcast.client.impl.protocol.codec.MapGetCodec)2 SqlMappingDdlCodec (com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IExecutorService (com.hazelcast.core.IExecutorService)2