use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapPartitionIterator method fetchWithPrefetchValues.
private List fetchWithPrefetchValues(HazelcastClientInstanceImpl client) {
ClientMessage request = MapFetchEntriesCodec.encodeRequest(mapProxy.getName(), encodePointers(pointers), fetchSize);
ClientInvocation clientInvocation = new ClientInvocation(client, request, mapProxy.getName(), partitionId);
try {
ClientInvocationFuture f = clientInvocation.invoke();
MapFetchEntriesCodec.ResponseParameters responseParameters = MapFetchEntriesCodec.decodeResponse(f.get());
IterationPointer[] pointers = decodePointers(responseParameters.iterationPointers);
setIterationPointers(responseParameters.entries, pointers);
return responseParameters.entries;
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientClusterViewListenerService method tryRegister.
private void tryRegister(Connection connection) {
if (!listenerAddedConnection.compareAndSet(null, connection)) {
// already registering/registered to another connection
return;
}
ClientMessage clientMessage = ClientAddClusterViewListenerCodec.encodeRequest();
ClientInvocation invocation = new ClientInvocation(client, clientMessage, null, connection);
ClusterViewListenerHandler handler = new ClusterViewListenerHandler(connection);
invocation.setEventHandler(handler);
handler.beforeListenerRegister(connection);
invocation.invokeUrgent().whenCompleteAsync((message, throwable) -> {
if (message != null) {
handler.onListenerRegister(connection);
return;
}
// completes with exception, listener needs to be reregistered
tryReregisterToRandomConnection(connection);
});
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapProxy method putAllInternal.
@SuppressWarnings("checkstyle:npathcomplexity")
private void putAllInternal(@Nonnull Map<? extends K, ? extends V> map, @Nullable InternalCompletableFuture<Void> future, boolean triggerMapLoader) {
if (map.isEmpty()) {
if (future != null) {
future.complete(null);
}
return;
}
checkNotNull(map, "Null argument map is not allowed");
ClientPartitionService partitionService = getContext().getPartitionService();
int partitionCount = partitionService.getPartitionCount();
Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<>(partitionCount);
for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
Data keyData = toData(entry.getKey());
int partitionId = partitionService.getPartitionId(keyData);
List<Map.Entry<Data, Data>> partition = entryMap.get(partitionId);
if (partition == null) {
partition = new ArrayList<>();
entryMap.put(partitionId, partition);
}
partition.add(new AbstractMap.SimpleEntry<>(keyData, toData(entry.getValue())));
}
assert entryMap.size() > 0;
AtomicInteger counter = new AtomicInteger(entryMap.size());
InternalCompletableFuture<Void> resultFuture = future != null ? future : new InternalCompletableFuture<>();
BiConsumer<ClientMessage, Throwable> callback = (response, t) -> {
if (t != null) {
resultFuture.completeExceptionally(t);
}
if (counter.decrementAndGet() == 0) {
finalizePutAll(map, entryMap);
if (!resultFuture.isDone()) {
resultFuture.complete(null);
}
}
};
for (Entry<Integer, List<Map.Entry<Data, 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 = MapPutAllCodec.encodeRequest(name, entry.getValue(), triggerMapLoader);
new ClientInvocation(getClient(), request, getName(), partitionId).invoke().whenCompleteAsync(callback);
}
// if executing in sync mode, block for the responses
if (future == null) {
try {
resultFuture.get();
} catch (Throwable e) {
throw rethrow(e);
}
}
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapProxy method subscribeToEventJournal.
@Override
public InternalCompletableFuture<EventJournalInitialSubscriberState> subscribeToEventJournal(int partitionId) {
final ClientMessage request = MapEventJournalSubscribeCodec.encodeRequest(name);
final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
return new ClientDelegatingFuture<>(fut, getSerializationService(), message -> {
ResponseParameters resp = MapEventJournalSubscribeCodec.decodeResponse(message);
return new EventJournalInitialSubscriberState(resp.oldestSequence, resp.newestSequence);
});
}
use of com.hazelcast.client.impl.spi.impl.ClientInvocation in project hazelcast by hazelcast.
the class ClientMapProxy method getAllInternal.
protected void getAllInternal(Set<K> keys, Map<Integer, List<Data>> partitionToKeyData, List<Object> resultingKeyValuePairs) {
if (partitionToKeyData.isEmpty()) {
fillPartitionToKeyData(keys, partitionToKeyData, null, null);
}
List<Future<ClientMessage>> futures = new ArrayList<>(partitionToKeyData.size());
for (Map.Entry<Integer, List<Data>> entry : partitionToKeyData.entrySet()) {
int partitionId = entry.getKey();
List<Data> keyList = entry.getValue();
if (!keyList.isEmpty()) {
ClientMessage request = MapGetAllCodec.encodeRequest(name, keyList);
futures.add(new ClientInvocation(getClient(), request, getName(), partitionId).invoke());
}
}
for (Future<ClientMessage> future : futures) {
try {
ClientMessage response = future.get();
List<Entry<Data, Data>> entries = MapGetAllCodec.decodeResponse(response);
for (Entry<Data, Data> entry : entries) {
resultingKeyValuePairs.add(entry.getKey());
resultingKeyValuePairs.add(entry.getValue());
}
} catch (Exception e) {
throw rethrow(e);
}
}
}
Aggregations