use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MasterContext method invokeOnParticipant.
private void invokeOnParticipant(MemberInfo memberInfo, Supplier<Operation> operationSupplier, @Nullable Consumer<Collection<Map.Entry<MemberInfo, Object>>> completionCallback, @Nullable BiConsumer<Address, Object> individualCallback, boolean retryOnTimeoutException, ConcurrentMap<MemberInfo, Object> collectedResponses, AtomicInteger remainingCount) {
Operation operation = operationSupplier.get();
InternalCompletableFuture<Object> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, operation, memberInfo.getAddress()).invoke();
future.whenCompleteAsync(withTryCatch(logger, (r, throwable) -> {
Object response = r != null ? r : throwable != null ? peel(throwable) : NULL_OBJECT;
if (retryOnTimeoutException && throwable instanceof OperationTimeoutException) {
logger.warning("Retrying " + operation.getClass().getName() + " that failed with " + OperationTimeoutException.class.getSimpleName() + " in " + jobIdString());
invokeOnParticipant(memberInfo, operationSupplier, completionCallback, individualCallback, retryOnTimeoutException, collectedResponses, remainingCount);
return;
}
if (individualCallback != null) {
individualCallback.accept(memberInfo.getAddress(), throwable != null ? peel(throwable) : r);
}
Object oldResponse = collectedResponses.put(memberInfo, response);
assert oldResponse == null : "Duplicate response for " + memberInfo.getAddress() + ". Old=" + oldResponse + ", new=" + response;
if (remainingCount.decrementAndGet() == 0 && completionCallback != null) {
completionCallback.accept(collectedResponses.entrySet().stream().map(e -> e.getValue() == NULL_OBJECT ? entry(e.getKey(), null) : e).collect(Collectors.toList()));
}
}));
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class JetInstanceImpl method getJobsInt.
@Override
public Map<Address, GetJobIdsResult> getJobsInt(String onlyName, Long onlyJobId) {
Map<Address, CompletableFuture<GetJobIdsResult>> futures = new HashMap<>();
Address masterAddress = null;
// if onlyName != null, only send the operation to master. Light jobs cannot have a name
Collection<Member> targetMembers = onlyName == null ? nodeEngine.getClusterService().getMembers(DATA_MEMBER_SELECTOR) : singleton(nodeEngine.getClusterService().getMembers().iterator().next());
for (Member member : targetMembers) {
if (masterAddress == null) {
masterAddress = member.getAddress();
}
GetJobIdsOperation operation = new GetJobIdsOperation(onlyName, onlyJobId);
InvocationFuture<GetJobIdsResult> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, operation, member.getAddress()).invoke();
futures.put(member.getAddress(), future);
}
Map<Address, GetJobIdsResult> res = new HashMap<>(futures.size());
for (Entry<Address, CompletableFuture<GetJobIdsResult>> en : futures.entrySet()) {
GetJobIdsResult result;
try {
result = en.getValue().get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
result = GetJobIdsResult.EMPTY;
} catch (ExecutionException e) {
// important. If we don't get response from the master, we report it to the user.
if (!en.getKey().equals(masterAddress) && (e.getCause() instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException)) {
result = GetJobIdsResult.EMPTY;
} else {
throw new RuntimeException("Error when getting job IDs: " + e, e);
}
}
res.put(en.getKey(), result);
}
return res;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class Util method assignPartitions.
/**
* Assigns given partitions to given {@code members}.
* Set of partitions belonging to non-members are assigned to
* {@code members} in a round robin fashion.
*/
public static Map<Address, List<Integer>> assignPartitions(Collection<Address> members0, Map<Address, List<Integer>> partitionsByOwner) {
assert !members0.isEmpty();
LinkedHashSet<Address> members = new LinkedHashSet<>(members0);
Iterator<Address> iterator = members.iterator();
Map<Address, List<Integer>> partitionsByMember = new HashMap<>();
for (Entry<Address, List<Integer>> entry : partitionsByOwner.entrySet()) {
Address partitionOwner = entry.getKey();
List<Integer> partitions = entry.getValue();
Address target;
if (members.contains(partitionOwner)) {
target = partitionOwner;
} else {
if (!iterator.hasNext()) {
iterator = members.iterator();
}
target = iterator.next();
}
partitionsByMember.merge(target, new ArrayList<>(partitions), (existing, incoming) -> {
existing.addAll(incoming);
return existing;
});
}
return partitionsByMember;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MapGetInvalidationMetaDataOperation method getOwnedPartitions.
private List<Integer> getOwnedPartitions() {
IPartitionService partitionService = getNodeEngine().getPartitionService();
Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
List<Integer> ownedPartitions = memberPartitionsMap.get(getNodeEngine().getThisAddress());
return ownedPartitions == null ? Collections.emptyList() : ownedPartitions;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MapClearExpiredOperation method isOwner.
private boolean isOwner() {
final NodeEngine nodeEngine = getNodeEngine();
final Address owner = nodeEngine.getPartitionService().getPartitionOwner(getPartitionId());
return nodeEngine.getThisAddress().equals(owner);
}
Aggregations