use of com.hazelcast.multimap.impl.MultiMapPartitionContainer in project hazelcast by hazelcast.
the class MultiMapTestUtil method getBackupMultiMap.
/**
* Returns all backup entries of an {@link MultiMap} by a given map name.
* <p>
* Note: This method returns all backups from all nodes and doesn't consider the replica indexes.
*
* @param instances the {@link HazelcastInstance} array to gather the data from
* @param multiMapName the MultiMap name
* @param <K> type of the key
* @param <V> type of the value
* @return a {@link Map} with the backup entries
*/
public static <K, V> Map<K, Collection<V>> getBackupMultiMap(HazelcastInstance[] instances, String multiMapName) {
Map<K, Collection<V>> map = new HashMap<K, Collection<V>>();
for (HazelcastInstance instance : instances) {
NodeEngineImpl nodeEngine = getNodeEngineImpl(instance);
MultiMapService mapService = nodeEngine.getService(MultiMapService.SERVICE_NAME);
InternalPartitionService partitionService = nodeEngine.getPartitionService();
SerializationService serializationService = nodeEngine.getSerializationService();
for (int partitionId = 0; partitionId < partitionService.getPartitionCount(); partitionId++) {
if (partitionService.isPartitionOwner(partitionId)) {
continue;
}
MultiMapPartitionContainer partitionContainer = mapService.getPartitionContainer(partitionId);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(multiMapName, false);
if (multiMapContainer == null) {
continue;
}
for (Map.Entry<Data, MultiMapValue> entry : multiMapContainer.getMultiMapValues().entrySet()) {
K key = serializationService.toObject(entry.getKey());
Collection<MultiMapRecord> collection = entry.getValue().getCollection(false);
Collection<V> values = new ArrayList<V>(collection.size());
for (MultiMapRecord record : collection) {
V value = serializationService.toObject(record.getObject());
values.add(value);
}
map.put(key, values);
}
}
}
return map;
}
Aggregations