-
Notifications
You must be signed in to change notification settings - Fork 43
/
Resolver.java
64 lines (53 loc) · 1.23 KB
/
Resolver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package jrds.starter;
import java.net.InetAddress;
import java.net.UnknownHostException;
import jrds.HostInfo;
import jrds.Probe;
import org.apache.log4j.Level;
public class Resolver extends Starter {
String hostname = "";
InetAddress address = null;
public Resolver(String hostname) {
this.hostname = hostname;
log(Level.DEBUG, "New dns resolver");
}
@Override
public boolean start() {
boolean started = false;
try {
address = InetAddress.getByName(hostname);
started = true;
} catch (UnknownHostException e) {
log(Level.ERROR, e, "DNS host name %s can't be found", hostname);
}
return started;
}
@Override
public void stop() {
address = null;
}
public InetAddress getInetAddress() {
return address;
}
@Override
public Object getKey() {
return "resolver:" + hostname;
}
public static Object makeKey(StarterNode node) {
HostInfo host = null;
if(node instanceof HostStarter)
host = ((HostStarter)node).getHost();
else if(node instanceof Probe<?,?>) {
Probe<?,?> p = (Probe<?,?>) node;
host = p.getHost();
}
else {
return null;
}
return "resolver:" + host.getDnsName();
}
@Deprecated
public static Object makeKey(String hostname) {
return "resolver:" + hostname;
}
}