use of com.hazelcast.client.impl.spi.ClientPartitionService 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.ClientPartitionService in project hazelcast by hazelcast.
the class ClientPartitionServiceLiteMemberTest method testWithLiteMemberAndDataMember.
@Test
public void testWithLiteMemberAndDataMember() {
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
factory.newHazelcastInstance(new Config().setLiteMember(true));
TestUtil.warmUpPartitions(hazelcastInstance);
HazelcastInstance client = factory.newHazelcastClient();
ClientPartitionService clientPartitionService = getClientPartitionService(client);
assertTrueEventually(() -> {
assertNotEquals(0, clientPartitionService.getPartitionCount());
assertNotNull(clientPartitionService.getPartitionOwner(0));
});
}
use of com.hazelcast.client.impl.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientCacheProxySupport method groupDataToPartitions.
private void groupDataToPartitions(Map<? extends K, ? extends V> userInputMap, List<Map.Entry<Data, Data>>[] entriesPerPartition, NearCachingHook nearCachingHook) {
ClientPartitionService partitionService = getContext().getPartitionService();
for (Map.Entry<? extends K, ? extends V> entry : userInputMap.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
validateNotNull(key, value);
Data keyData = toData(key);
Data valueData = toData(value);
nearCachingHook.beforeRemoteCall(key, keyData, value, valueData);
int partitionId = partitionService.getPartitionId(keyData);
List<Map.Entry<Data, Data>> entries = entriesPerPartition[partitionId];
if (entries == null) {
entries = new ArrayList<>();
entriesPerPartition[partitionId] = entries;
}
// TODO Can we do this without creating SimpleImmutableEntry?
entries.add(new AbstractMap.SimpleImmutableEntry<>(keyData, valueData));
}
}
use of com.hazelcast.client.impl.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientPartitionServiceLiteMemberTest method testWithOnlyLiteMember.
@Test
public void testWithOnlyLiteMember() {
factory.newHazelcastInstance(new Config().setLiteMember(true));
HazelcastInstance client = factory.newHazelcastClient();
ClientPartitionService clientPartitionService = getClientPartitionService(client);
assertTrueEventually(() -> assertEquals(271, clientPartitionService.getPartitionCount()));
assertNull(clientPartitionService.getPartitionOwner(0));
}
use of com.hazelcast.client.impl.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientMapProxy method iterator.
@Override
@Nonnull
public Iterator<Entry<K, V>> iterator() {
ClientPartitionService partitionService = getContext().getPartitionService();
int partitionCount = partitionService.getPartitionCount();
return new ClientMapIterator<>(this, partitionCount, false);
}
Aggregations