use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientInvokerWrapper method invokeOnAllPartitions.
@Override
public Object invokeOnAllPartitions(Object request) {
try {
ClientMessage clientRequest = (ClientMessage) request;
final Future future = new ClientInvocation(getClient(), clientRequest).invoke();
Object result = future.get();
return context.toObject(result);
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientInvokerWrapper method invokeOnPartitionOwner.
@Override
public Future invokeOnPartitionOwner(Object request, int partitionId) {
checkNotNull(request, "request cannot be null");
checkNotNegative(partitionId, "partitionId");
ClientMessage clientRequest = (ClientMessage) request;
ClientInvocation clientInvocation = new ClientInvocation(getClient(), clientRequest, partitionId);
return clientInvocation.invoke();
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceProxy method submitToPartition.
private <T> DurableExecutorServiceFuture<T> submitToPartition(Callable<T> task, int partitionId, T result) {
checkNotNull(task, "task should not be null");
SerializationService serService = getSerializationService();
ClientMessage request = DurableExecutorSubmitToPartitionCodec.encodeRequest(name, serService.toData(task));
int sequence;
try {
ClientMessage response = invokeOnPartition(request, partitionId);
sequence = DurableExecutorSubmitToPartitionCodec.decodeResponse(response).response;
} catch (Throwable t) {
return new ClientDurableExecutorServiceCompletedFuture<T>(t, getUserExecutor());
}
ClientMessage clientMessage = DurableExecutorRetrieveResultCodec.encodeRequest(name, sequence);
ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, partitionId).invoke();
long taskId = Bits.combineToLong(partitionId, sequence);
return new ClientDurableExecutorServiceDelegatingFuture<T>(future, serService, RETRIEVE_RESPONSE_DECODER, result, taskId);
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class AbstractClientCacheProxyBase method invoke.
protected ClientMessage invoke(ClientMessage clientMessage, Data keyData) {
try {
int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
Future future = new ClientInvocation((HazelcastClientInstanceImpl) clientContext.getHazelcastInstance(), clientMessage, partitionId).invoke();
return (ClientMessage) future.get();
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class CallbackAwareClientDelegatingFutureTest method test_CallbackAwareClientDelegatingFuture.
private void test_CallbackAwareClientDelegatingFuture(boolean timeout, boolean error) throws ExecutionException, InterruptedException {
if (timeout && error) {
throw new IllegalArgumentException("Only one of the `timeout` and `error` parameters can be enabled at the same time!");
}
int timeoutMillis = timeout ? 5000 : -1;
createCache(timeoutMillis, error);
ClientMessage getRequest = createGetRequest(1);
ClientMessageDecoder decoder = CACHE_GET_RESPONSE_DECODER;
ClientInvocation invocation = new ClientInvocation(client, getRequest, 0);
ClientInvocationFuture invocationFuture = invocation.invoke();
final AtomicBoolean responseCalled = new AtomicBoolean();
final AtomicBoolean failureCalled = new AtomicBoolean();
OneShotExecutionCallback callback = new OneShotExecutionCallback() {
@Override
protected void onResponseInternal(Object response) {
responseCalled.set(true);
}
@Override
protected void onFailureInternal(Throwable t) {
failureCalled.set(true);
}
};
CallbackAwareClientDelegatingFuture callbackAwareInvocationFuture = new CallbackAwareClientDelegatingFuture(invocationFuture, client.getSerializationService(), decoder, callback);
if (timeoutMillis > 0) {
try {
callbackAwareInvocationFuture.get(timeoutMillis / 2, TimeUnit.MILLISECONDS);
fail("Timeout expected!");
} catch (TimeoutException e) {
// Timeout expected
assertTrue(failureCalled.get());
assertFalse(responseCalled.get());
}
} else {
if (error) {
try {
callbackAwareInvocationFuture.get();
fail("CacheLoaderException expected!");
} catch (ExecutionException e) {
// Exception expected
assertTrue(e.getCause() instanceof CacheLoaderException);
assertTrue(failureCalled.get());
assertFalse(responseCalled.get());
}
} else {
try {
callbackAwareInvocationFuture.get();
assertTrue(responseCalled.get());
assertFalse(failureCalled.get());
} catch (CacheLoaderException e) {
fail("CacheLoaderException not expected!");
}
}
}
}
Aggregations