use of com.hazelcast.client.spi.impl.ClientInvocation 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.ClientInvocation 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.ClientInvocation in project hazelcast by hazelcast.
the class TransactionProxy method invoke.
private ClientMessage invoke(ClientMessage request) {
try {
final ClientInvocation clientInvocation = new ClientInvocation(client, request, connection);
final Future<ClientMessage> future = clientInvocation.invoke();
return future.get();
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientSmartListenerService method deregisterListener.
@Override
public boolean deregisterListener(final String userRegistrationId) {
Future<Boolean> future = registrationExecutor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
ClientRegistrationKey key = new ClientRegistrationKey(userRegistrationId);
Map<Connection, ClientEventRegistration> registrationMap = registrations.get(key);
if (registrationMap == null) {
return false;
}
boolean successful = true;
for (ClientEventRegistration registration : registrationMap.values()) {
Connection subscriber = registration.getSubscriber();
try {
ListenerMessageCodec listenerMessageCodec = registration.getCodec();
String serverRegistrationId = registration.getServerRegistrationId();
ClientMessage request = listenerMessageCodec.encodeRemoveRequest(serverRegistrationId);
new ClientInvocation(client, request, subscriber).invoke().get();
removeEventHandler(registration.getCallId());
registrationMap.remove(subscriber);
} catch (Exception e) {
successful = false;
logger.warning("Deregistration of listener with id " + userRegistrationId + " has failed to address " + subscriber.getEndPoint(), e);
}
}
if (successful) {
registrations.remove(key);
}
return successful;
}
});
try {
return future.get();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.spi.impl.ClientInvocation 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);
}
}
Aggregations