package org.onap.dmaap.datarouter.node;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.io.IOException;
import java.util.*;
import java.net.*;
private long nextcheck;
private String[] ips;
private String fqdn;
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(IsFrom.class);
/**
* Configure the JVM DNS cache to have a 10 second TTL. This needs to be called very very early or it won't have any effect.
long now = System.currentTimeMillis();
if (now > nextcheck) {
nextcheck = now + 10000;
- Vector<String> v = new Vector<String>();
+ ArrayList<String> hostAddrArray = new ArrayList<>();
try {
InetAddress[] addrs = InetAddress.getAllByName(fqdn);
- for (InetAddress a : addrs) {
- v.add(a.getHostAddress());
+ for (InetAddress addr : addrs) {
+ hostAddrArray.add(addr.getHostAddress());
}
- } catch (Exception e) {
+ } catch (UnknownHostException e) {
+ logger.error("IsFrom: UnknownHostEx: " + e.toString(), e);
+ }
+ ips = hostAddrArray.toArray(new String[0]);
+ logger.info("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips));
+ }
+ for (String ipAddr : ips) {
+ if (ipAddr.equals(ip)) {
+ return true;
}
- ips = v.toArray(new String[v.size()]);
}
- for (String s : ips) {
- if (s.equals(ip)) {
- return (true);
+ return false;
+ }
+
+ synchronized boolean isReachable(String ip) {
+ try {
+ if (InetAddress.getByName(ip).isReachable(1000)) {
+ return true;
}
+ } catch (UnknownHostException e) {
+ logger.error("IsFrom: UnknownHostEx: " + e.toString(), e);
+ } catch (IOException e) {
+ logger.error("IsFrom: Failed to parse IP : " + ip + " : " + e.toString(), e);
}
- return (false);
+ return false;
}
/**