use of com.hazelcast.multimap.impl.MultiMapProxyImpl.NULL_KEY_IS_NOT_ALLOWED in project hazelcast by hazelcast.
the class MultiMapProxySupport method putAllInternal.
// NB: this method is generally copied from MapProxySupport#putAllInternal
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:methodlength" })
protected void putAllInternal(Map<Data, Data> map, @Nullable InternalCompletableFuture<Void> future) {
// get partition to entries mapping
try {
int mapSize = map.size();
if (mapSize == 0) {
if (future != null) {
future.complete(null);
}
return;
}
int partitionCount = partitionService.getPartitionCount();
int initialSize = getPutAllInitialSize(mapSize, partitionCount);
// get node to partition mapping
Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
// fill entriesPerPartition
MapEntries[] entriesPerPartition = new MapEntries[partitionCount];
for (Map.Entry<Data, 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);
MapEntries entries = entriesPerPartition[partitionId];
if (entries == null) {
entries = new MapEntries(initialSize);
entriesPerPartition[partitionId] = entries;
}
entries.add(keyData, entry.getValue());
}
// invoke operations for entriesPerPartition
AtomicInteger counter = new AtomicInteger(memberPartitionsMap.size());
InternalCompletableFuture<Void> resultFuture = future != null ? future : new InternalCompletableFuture<>();
BiConsumer<Void, Throwable> callback = (response, t) -> {
if (t != null) {
resultFuture.completeExceptionally(t);
}
if (counter.decrementAndGet() == 0) {
if (!resultFuture.isDone()) {
resultFuture.complete(null);
}
}
};
for (Map.Entry<Address, List<Integer>> entry : memberPartitionsMap.entrySet()) {
invokePutAllOperation(entry.getKey(), entry.getValue(), entriesPerPartition).whenCompleteAsync(callback);
}
// if executing in sync mode, block for the responses
if (future == null) {
resultFuture.get();
}
} catch (Throwable e) {
throw rethrow(e);
}
}
Aggregations