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();
}
}
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);
}
}
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);
}
}
}
}
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;
}
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;
}
Aggregations