use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceProxy method retrieveAndDisposeResult.
@Override
public <T> Future<T> retrieveAndDisposeResult(long taskId) {
int partitionId = Bits.extractInt(taskId, false);
int sequence = Bits.extractInt(taskId, true);
ClientMessage clientMessage = DurableExecutorRetrieveAndDisposeResultCodec.encodeRequest(name, sequence);
ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, partitionId).invoke();
return new ClientDelegatingFuture<T>(future, getSerializationService(), RETRIEVE_RESPONSE_DECODER);
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class ClientExecutorServiceProxy method submitToRandomInternal.
private <T> void submitToRandomInternal(Callable<T> task, ExecutionCallback<T> callback) {
checkNotNull(task, "task should not be null");
String uuid = getUUID();
int partitionId = randomPartitionId();
ClientMessage request = ExecutorServiceSubmitToPartitionCodec.encodeRequest(name, uuid, toData(task), partitionId);
ClientInvocationFuture f = invokeOnPartitionOwner(request, partitionId);
SerializationService serializationService = getContext().getSerializationService();
ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(f, serializationService, SUBMIT_TO_PARTITION_DECODER);
delegatingFuture.andThen(callback);
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class ClientExecutorServiceProxy method submitToKeyOwnerInternal.
private <T> void submitToKeyOwnerInternal(Callable<T> task, Object key, ExecutionCallback<T> callback) {
checkNotNull(task, "task should not be null");
String uuid = getUUID();
int partitionId = getPartitionId(key);
ClientMessage request = ExecutorServiceSubmitToPartitionCodec.encodeRequest(name, uuid, toData(task), partitionId);
ClientInvocationFuture f = invokeOnPartitionOwner(request, partitionId);
SerializationService serializationService = getContext().getSerializationService();
ClientDelegatingFuture<T> delegatingFuture = new ClientDelegatingFuture<T>(f, serializationService, SUBMIT_TO_PARTITION_DECODER);
delegatingFuture.andThen(callback);
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class AbstractClientCacheProxy method getInternal.
protected Object getInternal(final K key, ExpiryPolicy expiryPolicy, boolean async) {
final long start = System.nanoTime();
ensureOpen();
validateNotNull(key);
final Data keyData = toData(key);
Object cached = getCachedValue(keyData, !async);
if (cached != NOT_CACHED) {
return asCompletedFutureOrValue(cached, async);
}
final long reservationId = tryReserveForUpdate(keyData);
final Data expiryPolicyData = toData(expiryPolicy);
ClientMessage request = CacheGetCodec.encodeRequest(nameWithPrefix, keyData, expiryPolicyData);
ClientInvocationFuture future;
try {
final int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
final ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
future = clientInvocation.invoke();
} catch (Throwable t) {
invalidateNearCache(keyData);
throw rethrow(t);
}
SerializationService serializationService = clientContext.getSerializationService();
ClientDelegatingFuture<V> delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, cacheGetResponseDecoder);
if (async) {
if (nearCache != null) {
delegatingFuture.andThenInternal(new ExecutionCallback<Data>() {
public void onResponse(Data valueData) {
storeInNearCache(keyData, valueData, null, reservationId, false);
if (statisticsEnabled) {
handleStatisticsOnGet(start, valueData);
}
}
public void onFailure(Throwable t) {
invalidateNearCache(keyData);
}
}, false);
}
return delegatingFuture;
} else {
try {
V value = toObject(delegatingFuture.get());
if (nearCache != null) {
storeInNearCache(keyData, (Data) delegatingFuture.getResponse(), value, reservationId, false);
}
if (statisticsEnabled) {
handleStatisticsOnGet(start, value);
}
return value;
} catch (Throwable e) {
invalidateNearCache(keyData);
throw rethrowAllowedTypeFirst(e, CacheException.class);
}
}
}
use of com.hazelcast.client.util.ClientDelegatingFuture in project hazelcast by hazelcast.
the class AbstractClientCacheProxyBase method submitLoadAllTask.
protected void submitLoadAllTask(ClientMessage request, CompletionListener completionListener, final Set<Data> keys) {
final CompletionListener compListener = completionListener != null ? completionListener : NULL_COMPLETION_LISTENER;
ClientDelegatingFuture<V> delegatingFuture = null;
try {
injectDependencies(completionListener);
final long start = System.nanoTime();
ClientInvocationFuture future = new ClientInvocation((HazelcastClientInstanceImpl) clientContext.getHazelcastInstance(), request).invoke();
SerializationService serializationService = clientContext.getSerializationService();
delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, LOAD_ALL_DECODER);
final Future delFuture = delegatingFuture;
loadAllCalls.put(delegatingFuture, compListener);
delegatingFuture.andThen(new ExecutionCallback<V>() {
@Override
public void onResponse(V response) {
loadAllCalls.remove(delFuture);
onLoadAll(keys, response, start, System.nanoTime());
compListener.onCompletion();
}
@Override
public void onFailure(Throwable t) {
loadAllCalls.remove(delFuture);
handleFailureOnCompletionListener(compListener, t);
}
});
} catch (Throwable t) {
if (delegatingFuture != null) {
loadAllCalls.remove(delegatingFuture);
}
handleFailureOnCompletionListener(compListener, t);
}
}
Aggregations