use of com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult 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;
}
Aggregations