use of com.hazelcast.client.spi.impl.ClientInvocationFuture 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.spi.impl.ClientInvocationFuture 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);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class ClientAddressCancellableDelegatingFuture method invokeCancelRequest.
private boolean invokeCancelRequest(boolean mayInterruptIfRunning) throws InterruptedException {
waitForRequestToBeSend();
ClientInvocation clientInvocation;
final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
ClientMessage request = ExecutorServiceCancelOnAddressCodec.encodeRequest(uuid, target, mayInterruptIfRunning);
clientInvocation = new ClientInvocation(client, request, target);
try {
ClientInvocationFuture f = clientInvocation.invoke();
return ExecutorServiceCancelOnAddressCodec.decodeResponse(f.get()).response;
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture 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!");
}
}
}
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture 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);
}
}
Aggregations