use of com.hazelcast.client.impl.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientCacheProxySupport method groupKeysToPartitions.
private List<Data>[] groupKeysToPartitions(Set<? extends K> keys, Set<Data> serializedKeys) {
List<Data>[] keysByPartition = new List[partitionCount];
ClientPartitionService partitionService = getContext().getPartitionService();
for (K key : keys) {
Data keyData = getSerializationService().toData(key);
if (serializedKeys != null) {
serializedKeys.add(keyData);
}
int partitionId = partitionService.getPartitionId(keyData);
List<Data> partition = keysByPartition[partitionId];
if (partition == null) {
partition = new ArrayList<>();
keysByPartition[partitionId] = partition;
}
partition.add(keyData);
}
return keysByPartition;
}
use of com.hazelcast.client.impl.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientCacheProxySupport method onInitialize.
@Override
protected void onInitialize() {
logger = getContext().getLoggingService().getLogger(getClass());
statsHandler = new CacheStatsHandler(getSerializationService());
ClientPartitionService partitionService = getContext().getPartitionService();
partitionCount = partitionService.getPartitionCount();
}
use of com.hazelcast.client.impl.spi.ClientPartitionService 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.ClientPartitionService in project hazelcast by hazelcast.
the class ClientMapProxy method iterator.
@Override
@Nonnull
public Iterator<Entry<K, V>> iterator(int fetchSize) {
ClientPartitionService partitionService = getContext().getPartitionService();
int partitionCount = partitionService.getPartitionCount();
return new ClientMapIterator<>(this, fetchSize, partitionCount, false);
}
use of com.hazelcast.client.impl.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientMapProxy method fillPartitionToKeyData.
protected void fillPartitionToKeyData(Set<K> keys, Map<Integer, List<Data>> partitionToKeyData, Map<Object, Data> keyMap, Map<Data, Object> reverseKeyMap) {
ClientPartitionService partitionService = getContext().getPartitionService();
for (K key : keys) {
Data keyData = toData(key);
int partitionId = partitionService.getPartitionId(keyData);
List<Data> keyList = partitionToKeyData.get(partitionId);
if (keyList == null) {
keyList = new ArrayList<>();
partitionToKeyData.put(partitionId, keyList);
}
keyList.add(keyData);
if (keyMap != null) {
keyMap.put(key, keyData);
}
if (reverseKeyMap != null) {
reverseKeyMap.put(keyData, key);
}
}
}
Aggregations