use of com.hazelcast.client.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientMapProxy method getAll.
@Override
@SuppressWarnings("unchecked")
public Map<K, V> getAll(Set<K> keys) {
if (CollectionUtil.isEmpty(keys)) {
return emptyMap();
}
Map<Integer, List<Data>> partitionToKeyData = new HashMap<Integer, List<Data>>();
ClientPartitionService partitionService = getContext().getPartitionService();
for (Object key : keys) {
Data keyData = toData(key);
int partitionId = partitionService.getPartitionId(keyData);
List<Data> keyList = partitionToKeyData.get(partitionId);
if (keyList == null) {
keyList = new ArrayList<Data>();
partitionToKeyData.put(partitionId, keyList);
}
keyList.add(keyData);
}
Map<K, V> result = new HashMap<K, V>();
getAllInternal(partitionToKeyData, result);
return result;
}
use of com.hazelcast.client.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientMapProxy method putAll.
@Override
public void putAll(Map<? extends K, ? extends V> m) {
ClientPartitionService partitionService = getContext().getPartitionService();
Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<Integer, List<Map.Entry<Data, Data>>>(partitionService.getPartitionCount());
for (Entry<? extends K, ? extends V> entry : m.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<Map.Entry<Data, Data>>();
entryMap.put(partitionId, partition);
}
partition.add(new AbstractMap.SimpleEntry<Data, Data>(keyData, toData(entry.getValue())));
}
putAllInternal(entryMap);
}
use of com.hazelcast.client.spi.ClientPartitionService in project hazelcast by hazelcast.
the class AbstractClientCacheProxy method putAll.
@Override
public void putAll(Map<? extends K, ? extends V> map, ExpiryPolicy expiryPolicy) {
final long start = System.nanoTime();
ensureOpen();
validateNotNull(map);
try {
ClientPartitionService partitionService = clientContext.getPartitionService();
int partitionCount = partitionService.getPartitionCount();
// First we fill entry set per partition
List<Map.Entry<Data, Data>>[] entriesPerPartition = groupDataToPartitions(map, partitionService, partitionCount);
// Then we invoke the operations and sync on completion of these operations
putToAllPartitionsAndWaitForCompletion(entriesPerPartition, expiryPolicy, start);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.client.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceProxy method onInitialize.
@Override
protected void onInitialize() {
ClientContext context = getContext();
ClientPartitionService partitionService = context.getPartitionService();
partitionCount = partitionService.getPartitionCount();
}
use of com.hazelcast.client.spi.ClientPartitionService in project hazelcast by hazelcast.
the class ClientPartitionServiceLiteMemberTest method testPartitionsBlockingSucceedsWithLiteMemberAndDataMember.
@Test
public void testPartitionsBlockingSucceedsWithLiteMemberAndDataMember() {
factory.newHazelcastInstance();
factory.newHazelcastInstance(new Config().setLiteMember(true));
final HazelcastInstance client = factory.newHazelcastClient();
final ClientPartitionService clientPartitionService = getClientPartitionService(client);
assertNotNull(clientPartitionService.getPartitionOwner(0));
}
Aggregations