use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapProxy method readFromEventJournal.
@Override
public <T> InternalCompletableFuture<ReadResultSet<T>> readFromEventJournal(long startSequence, int minSize, int maxSize, int partitionId, java.util.function.Predicate<? super EventJournalMapEvent<K, V>> predicate, java.util.function.Function<? super EventJournalMapEvent<K, V>, ? extends T> projection) {
if (maxSize < minSize) {
throw new IllegalArgumentException("maxSize " + maxSize + " must be greater or equal to minSize " + minSize);
}
final SerializationService ss = getSerializationService();
final ClientMessage request = MapEventJournalReadCodec.encodeRequest(name, startSequence, minSize, maxSize, ss.toData(predicate), ss.toData(projection));
final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
return new ClientDelegatingFuture<>(fut, ss, message -> {
MapEventJournalReadCodec.ResponseParameters params = MapEventJournalReadCodec.decodeResponse(message);
ReadResultSetImpl resultSet = new ReadResultSetImpl<>(params.readCount, params.items, params.itemSeqs, params.nextSeq);
resultSet.setSerializationService(getSerializationService());
return resultSet;
});
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMultiMapProxy method putAllInternal.
@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
private void putAllInternal(@Nonnull Map<Data, Collection<Data>> map, @Nonnull InternalCompletableFuture<Void> future) {
if (map.isEmpty()) {
future.complete(null);
return;
}
ClientPartitionService partitionService = getContext().getPartitionService();
int partitionCount = partitionService.getPartitionCount();
Map<Integer, Collection<Map.Entry<Data, Collection<Data>>>> entryMap = new HashMap<>(partitionCount);
for (Map.Entry<Data, Collection<Data>> entry : map.entrySet()) {
checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
Data keyData = entry.getKey();
int partitionId = partitionService.getPartitionId(keyData);
Collection<Map.Entry<Data, Collection<Data>>> partition = entryMap.get(partitionId);
if (partition == null) {
partition = new ArrayList<>();
entryMap.put(partitionId, partition);
}
partition.add(new AbstractMap.SimpleEntry<>(keyData, entry.getValue()));
}
assert entryMap.size() > 0;
AtomicInteger counter = new AtomicInteger(entryMap.size());
InternalCompletableFuture<Void> resultFuture = future;
BiConsumer<ClientMessage, Throwable> callback = (response, t) -> {
if (t != null) {
resultFuture.completeExceptionally(t);
}
if (counter.decrementAndGet() == 0) {
if (!resultFuture.isDone()) {
resultFuture.complete(null);
}
}
};
for (Map.Entry<Integer, Collection<Map.Entry<Data, Collection<Data>>>> entry : entryMap.entrySet()) {
Integer partitionId = entry.getKey();
// if there is only one entry, consider how we can use MapPutRequest
// without having to get back the return value
ClientMessage request = MultiMapPutAllCodec.encodeRequest(name, entry.getValue());
new ClientInvocation(getClient(), request, getName(), partitionId).invoke().whenCompleteAsync(callback);
}
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceProxy method submitToPartition.
private <T> DurableExecutorServiceFuture<T> submitToPartition(@Nonnull Callable<T> task, int partitionId, @Nullable T result) {
checkNotNull(task, "task should not be null");
ClientMessage request = DurableExecutorSubmitToPartitionCodec.encodeRequest(name, toData(task));
int sequence;
try {
ClientMessage response = invokeOnPartition(request, partitionId);
sequence = DurableExecutorSubmitToPartitionCodec.decodeResponse(response);
} catch (Throwable t) {
return completedExceptionally(t, ConcurrencyUtil.getDefaultAsyncExecutor());
}
ClientMessage clientMessage = DurableExecutorRetrieveResultCodec.encodeRequest(name, sequence);
ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, getName(), partitionId).invoke();
long taskId = Bits.combineToLong(partitionId, sequence);
return new ClientDurableExecutorServiceDelegatingFuture<>(future, getSerializationService(), DurableExecutorRetrieveResultCodec::decodeResponse, result, taskId);
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation 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, getName(), partitionId).invoke();
return new ClientDelegatingFuture<>(future, getSerializationService(), DurableExecutorRetrieveResultCodec::decodeResponse);
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientFlakeIdGeneratorProxy method newIdBatch.
private IdBatch newIdBatch(int batchSize) {
ClientMessage requestMsg = FlakeIdGeneratorNewIdBatchCodec.encodeRequest(name, batchSize);
ClientMessage responseMsg = new ClientInvocation(getClient(), requestMsg, getName()).invoke().joinInternal();
ResponseParameters response = FlakeIdGeneratorNewIdBatchCodec.decodeResponse(responseMsg);
return new IdBatch(response.base, response.increment, response.batchSize);
}
Aggregations