Search in sources :

Example 11 with ClientDelegatingFuture

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

the class ClientMaxAllowedInvocationTest method testMaxAllowed_withUnfinishedCallback.

@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withUnfinishedCallback() throws ExecutionException, InterruptedException {
    int MAX_ALLOWED = 10;
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    String name = randomString();
    IMap map = client.getMap(name);
    IExecutorService executorService = client.getExecutorService(randomString());
    for (int i = 0; i < MAX_ALLOWED - 1; i++) {
        executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
    }
    ClientDelegatingFuture future = (ClientDelegatingFuture) executorService.submit(new SleepyProcessor(2000));
    CountDownLatch countDownLatch = new CountDownLatch(1);
    future.andThenInternal(new SleepyCallback(countDownLatch), false);
    future.get();
    try {
        map.get(1);
    } catch (HazelcastOverloadException e) {
        throw e;
    } finally {
        countDownLatch.countDown();
    }
}
Also used : IMap(com.hazelcast.core.IMap) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) IExecutorService(com.hazelcast.core.IExecutorService) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with ClientDelegatingFuture

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

the class ClientRingbufferProxy method readManyAsync.

@Override
public ICompletableFuture<ReadResultSet<E>> readManyAsync(long startSequence, int minCount, int maxCount, IFunction<E, Boolean> filter) {
    checkSequence(startSequence);
    checkNotNegative(minCount, "minCount can't be smaller than 0");
    checkTrue(maxCount >= minCount, "maxCount should be equal or larger than minCount");
    checkTrue(minCount <= capacity(), "the minCount should be smaller than or equal to the capacity");
    checkTrue(maxCount <= MAX_BATCH_SIZE, "maxCount can't be larger than " + MAX_BATCH_SIZE);
    ClientMessage request = RingbufferReadManyCodec.encodeRequest(name, startSequence, minCount, maxCount, toData(filter));
    try {
        ClientInvocationFuture invocationFuture = new ClientInvocation(getClient(), request, partitionId).invoke();
        return new ClientDelegatingFuture<ReadResultSet<E>>(invocationFuture, getContext().getSerializationService(), readManyAsyncResponseDecoder);
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) MAX_BATCH_SIZE(com.hazelcast.ringbuffer.impl.RingbufferProxy.MAX_BATCH_SIZE) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ExecutionException(java.util.concurrent.ExecutionException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 13 with ClientDelegatingFuture

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

the class AbstractClientInternalCacheProxy method putInternalSync.

private Object putInternalSync(V value, boolean isGet, long start, Data keyData, Data valueData, ClientInvocationFuture future) {
    try {
        ClientDelegatingFuture delegatingFuture = new ClientDelegatingFuture(future, clientContext.getSerializationService(), PUT_RESPONSE_DECODER);
        Object response = delegatingFuture.get();
        if (statisticsEnabled) {
            handleStatisticsOnPut(isGet, start, response);
        }
        return response;
    } catch (Throwable e) {
        throw rethrowAllowedTypeFirst(e, CacheException.class);
    } finally {
        if (nearCache != null) {
            if (cacheOnUpdate) {
                storeInNearCache(keyData, valueData, value, NOT_RESERVED, cacheOnUpdate);
            } else {
                invalidateNearCache(keyData);
            }
        }
    }
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheException(javax.cache.CacheException)

Example 14 with ClientDelegatingFuture

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

the class AbstractClientInternalCacheProxy method replaceInternal.

protected <T> ICompletableFuture<T> replaceInternal(K key, V oldValue, V newValue, ExpiryPolicy expiryPolicy, boolean hasOldValue, boolean withCompletionEvent, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    if (hasOldValue) {
        validateNotNull(key, oldValue, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue, newValue);
    } else {
        validateNotNull(key, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, newValue);
    }
    Data keyData = toData(key);
    Data oldValueData = toData(oldValue);
    Data newValueData = toData(newValue);
    Data expiryPolicyData = toData(expiryPolicy);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheReplaceCodec.encodeRequest(nameWithPrefix, keyData, oldValueData, newValueData, expiryPolicyData, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
        invalidateNearCache(keyData);
    } catch (Exception e) {
        throw rethrow(e);
    }
    ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(future, clientContext.getSerializationService(), REPLACE_RESPONSE_DECODER);
    if (async && statisticsEnabled) {
        delegatingFuture.andThenInternal(new ExecutionCallback<T>() {

            public void onResponse(T response) {
                handleStatisticsOnReplace(false, start, response);
            }

            public void onFailure(Throwable t) {
            }
        }, true);
    }
    return delegatingFuture;
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheEventData(com.hazelcast.cache.impl.CacheEventData) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 15 with ClientDelegatingFuture

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

the class AbstractClientInternalCacheProxy method replaceAndGetAsyncInternal.

protected <T> ICompletableFuture<T> replaceAndGetAsyncInternal(K key, V oldValue, V newValue, ExpiryPolicy expiryPolicy, boolean hasOldValue, boolean withCompletionEvent, boolean async) {
    final long start = System.nanoTime();
    ensureOpen();
    if (hasOldValue) {
        validateNotNull(key, oldValue, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue, newValue);
    } else {
        validateNotNull(key, newValue);
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, newValue);
    }
    Data keyData = toData(key);
    Data newValueData = toData(newValue);
    Data expiryPolicyData = toData(expiryPolicy);
    int completionId = withCompletionEvent ? nextCompletionId() : -1;
    ClientMessage request = CacheGetAndReplaceCodec.encodeRequest(nameWithPrefix, keyData, newValueData, expiryPolicyData, completionId);
    ClientInvocationFuture future;
    try {
        future = invoke(request, keyData, completionId);
        invalidateNearCache(keyData);
    } catch (Exception e) {
        throw rethrow(e);
    }
    ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(future, clientContext.getSerializationService(), GET_AND_REPLACE_RESPONSE_DECODER);
    if (async && statisticsEnabled) {
        delegatingFuture.andThenInternal(new ExecutionCallback<T>() {

            public void onResponse(T response) {
                handleStatisticsOnReplace(true, start, response);
            }

            public void onFailure(Throwable t) {
            }
        }, true);
    }
    return delegatingFuture;
}
Also used : ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) CacheEventData(com.hazelcast.cache.impl.CacheEventData) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) CacheException(javax.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Aggregations

ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)20 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)17 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)16 Data (com.hazelcast.nio.serialization.Data)8 SerializationService (com.hazelcast.spi.serialization.SerializationService)8 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)7 ExecutionException (java.util.concurrent.ExecutionException)7 CacheException (javax.cache.CacheException)6 CacheEventData (com.hazelcast.cache.impl.CacheEventData)5 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)4 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)3 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)2 HazelcastException (com.hazelcast.core.HazelcastException)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastOverloadException (com.hazelcast.core.HazelcastOverloadException)1 IExecutorService (com.hazelcast.core.IExecutorService)1 IMap (com.hazelcast.core.IMap)1 MAX_BATCH_SIZE (com.hazelcast.ringbuffer.impl.RingbufferProxy.MAX_BATCH_SIZE)1