use of com.hazelcast.client.spi.impl.ClientInvocationFuture 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.spi.impl.ClientInvocationFuture 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;
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class AbstractClientInternalCacheProxy method invoke.
protected ClientInvocationFuture invoke(ClientMessage req, int partitionId, int completionId) {
boolean completionOperation = completionId != -1;
if (completionOperation) {
registerCompletionLatch(completionId, 1);
}
try {
HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
ClientInvocation clientInvocation = new ClientInvocation(client, req, partitionId);
ClientInvocationFuture f = clientInvocation.invoke();
if (completionOperation) {
waitCompletionLatch(completionId, f);
}
return f;
} catch (Throwable e) {
if (e instanceof IllegalStateException) {
close();
}
if (completionOperation) {
deregisterCompletionLatch(completionId);
}
throw rethrowAllowedTypeFirst(e, CacheException.class);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class AbstractClientInternalCacheProxy method removeAsyncInternal.
protected <T> ICompletableFuture<T> removeAsyncInternal(K key, V oldValue, boolean hasOldValue, boolean withCompletionEvent, boolean async) {
final long start = System.nanoTime();
ensureOpen();
if (hasOldValue) {
validateNotNull(key, oldValue);
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue);
} else {
validateNotNull(key);
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
}
Data keyData = toData(key);
Data oldValueData = toData(oldValue);
int completionId = withCompletionEvent ? nextCompletionId() : -1;
ClientMessage request = CacheRemoveCodec.encodeRequest(nameWithPrefix, keyData, oldValueData, 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(), REMOVE_RESPONSE_DECODER);
if (async && statisticsEnabled) {
delegatingFuture.andThenInternal(new ExecutionCallback<T>() {
public void onResponse(T response) {
handleStatisticsOnRemove(false, start, response);
}
public void onFailure(Throwable t) {
}
}, true);
}
return delegatingFuture;
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class ClientMapPartitionIterator method fetchWithoutPrefetchValues.
private List fetchWithoutPrefetchValues(HazelcastClientInstanceImpl client) {
ClientMessage request = MapFetchKeysCodec.encodeRequest(mapProxy.getName(), partitionId, lastTableIndex, fetchSize);
ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
try {
ClientInvocationFuture f = clientInvocation.invoke();
MapFetchKeysCodec.ResponseParameters responseParameters = MapFetchKeysCodec.decodeResponse(f.get());
setLastTableIndex(responseParameters.keys, responseParameters.tableIndex);
return responseParameters.keys;
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
Aggregations