use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class AbstractClientInternalCacheProxy method getAndRemoveAsyncInternal.
protected <T> ICompletableFuture<T> getAndRemoveAsyncInternal(K key, boolean withCompletionEvent, boolean async) {
final long start = System.nanoTime();
ensureOpen();
validateNotNull(key);
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
final Data keyData = toData(key);
final int completionId = withCompletionEvent ? nextCompletionId() : -1;
ClientMessage request = CacheGetAndRemoveCodec.encodeRequest(nameWithPrefix, keyData, 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_REMOVE_RESPONSE_DECODER);
if (async && statisticsEnabled) {
delegatingFuture.andThenInternal(new ExecutionCallback<T>() {
public void onResponse(T response) {
handleStatisticsOnRemove(true, 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 putIfAbsentInternal.
protected Object putIfAbsentInternal(K key, V value, ExpiryPolicy expiryPolicy, boolean withCompletionEvent, boolean async) {
long start = System.nanoTime();
ensureOpen();
validateNotNull(key, value);
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, value);
Data keyData = toData(key);
Data valueData = toData(value);
Data expiryPolicyData = toData(expiryPolicy);
int completionId = withCompletionEvent ? nextCompletionId() : -1;
ClientMessage request = CachePutIfAbsentCodec.encodeRequest(nameWithPrefix, keyData, valueData, expiryPolicyData, completionId);
ClientInvocationFuture future;
try {
future = invoke(request, keyData, completionId);
} catch (Throwable t) {
throw rethrow(t);
}
ClientDelegatingFuture<Boolean> delegatingFuture = new ClientDelegatingFuture<Boolean>(future, clientContext.getSerializationService(), PUT_IF_ABSENT_RESPONSE_DECODER);
if (async) {
return putIfAbsentInternalAsync(value, start, keyData, valueData, delegatingFuture);
}
return putIfAbsentInternalSync(value, start, keyData, valueData, delegatingFuture);
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class ClientMapProxy method getAsyncInternal.
protected ICompletableFuture<V> getAsyncInternal(Data keyData) {
SerializationService serializationService = getContext().getSerializationService();
ClientMessage request = MapGetCodec.encodeRequest(name, keyData, getThreadId());
try {
ClientInvocationFuture future = invokeOnKeyOwner(request, keyData);
return new ClientDelegatingFuture<V>(future, serializationService, GET_ASYNC_RESPONSE_DECODER);
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class ClientRingbufferProxy method addAllAsync.
@Override
public ICompletableFuture<Long> addAllAsync(Collection<? extends E> collection, OverflowPolicy overflowPolicy) {
checkNotNull(collection, "collection can't be null");
checkNotNull(overflowPolicy, "overflowPolicy can't be null");
checkFalse(collection.isEmpty(), "collection can't be empty");
checkTrue(collection.size() <= MAX_BATCH_SIZE, "collection can't be larger than " + MAX_BATCH_SIZE);
Collection<Data> dataCollection = CollectionUtil.objectToDataCollection(collection, getSerializationService());
ClientMessage request = RingbufferAddAllCodec.encodeRequest(name, dataCollection, overflowPolicy.getId());
try {
ClientInvocationFuture invocationFuture = new ClientInvocation(getClient(), request, partitionId).invoke();
return new ClientDelegatingFuture<Long>(invocationFuture, getContext().getSerializationService(), ADD_ALL_ASYNC_RESPONSE_DECODER);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class ClientRingbufferProxy method addAsync.
@Override
public ICompletableFuture<Long> addAsync(E item, OverflowPolicy overflowPolicy) {
checkNotNull(item, "item can't be null");
checkNotNull(overflowPolicy, "overflowPolicy can't be null");
Data element = toData(item);
ClientMessage request = RingbufferAddCodec.encodeRequest(name, overflowPolicy.getId(), element);
try {
ClientInvocationFuture invocationFuture = new ClientInvocation(getClient(), request, partitionId).invoke();
return new ClientDelegatingFuture<Long>(invocationFuture, getContext().getSerializationService(), ADD_ASYNC_ASYNC_RESPONSE_DECODER);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
Aggregations