( ). - , .
TcpDiscoverySpi resolvedAddresses(), , .
This solution is not ideal, because now, if NodeAnot found NodeB, he will never try to find NodeB. However, this is not a showstopper, because from the beginning NodeBhe reaches NodeA, and they begin to talk to each other. Therefore, an effective Rolling Updates mechanism works for me.
The method isCandidateRespondis a quick-resolving solution and, most likely, will vary depending on the specific case.
Here is the code snippet:
public class TcpDiscoverySpiPrecheckingImpl extends TcpDiscoverySpi {
private Logger log = Logger.getLogger(getClass());
@Override
protected Collection<InetSocketAddress> resolvedAddresses() throws IgniteSpiException {
Collection<InetSocketAddress> candidates = super.resolvedAddresses();
Collection<InetSocketAddress> approved = new ArrayList<>();
for (InetSocketAddress candidate : candidates) {
if (isCandidateRespond(candidate)) {
approved.add(candidate);
}
}
return approved;
}
private boolean isCandidateRespond(InetSocketAddress candidate) {
if (log.isTraceEnabled()) {
log.trace("Checking if remote node responds: " + candidate);
}
URL url = null;
try {
url = new URL("http://" + candidate.getHostName() + "/");
try (InputStream stream = url.openStream()) {
return true;
}
} catch (Throwable t) {
log.info("Candidate remote node didn't respond: " + url + ". Reason: " + t.getMessage());
return false;
}
}
}
source
share