public static <K, V> Map<Address, Map<K, V>> mapResultToMember(JobSupervisor supervisor, Map<K, V> result) {
Set<Object> unassignedKeys = new HashSet<Object>();
for (Map.Entry<K, V> entry : result.entrySet()) {
Address address = supervisor.getReducerAddressByKey(entry.getKey());
if (address == null) {
unassignedKeys.add(entry.getKey());
}
}
if (unassignedKeys.size() > 0) {
requestAssignment(unassignedKeys, supervisor);
}
// Now assign all keys
Map<Address, Map<K, V>> mapping = new HashMap<Address, Map<K, V>>();
for (Map.Entry<K, V> entry : result.entrySet()) {
Address address = supervisor.getReducerAddressByKey(entry.getKey());
if (address != null) {
Map<K, V> data = mapping.get(address);
if (data == null) {
data = new HashMap<K, V>();
mapping.put(address, data);