I need to call a web service that performs work for my application. To use the service, you send a token with each request so you can later identify each job. The service provides reporting with a second call, which outputs logging-style records for all work it's performed, regardless of which client or application is fetching the report. The token is the key to finding your own records. I plan on using the form "appid-ipaddress-jobid". By using the ipaddress in my token, I can run several instances of my application (each on it's own server) and identify only the jobs specific to each server.
To get the ip address of each machine, I was planning on using code similar to:
List<String> addressList = new ArrayList<String>();
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
addressList.add(address.getHostAddress());
}
}
If the machine has more than one ip address (or another network card is added later), I'll have to add a little logic when parsing records, but that's no big deal. However, I'm unclear what's going to happen if any instances of my application get moved to a cluster. Say an instance of my application is brought up in a cluster (this will likely be Terracotta, but I'm open to other solutions). Would NetworkInterface see a common set of interfaces? If the above code runs in a singleton, will the results I get after a restart vary based on which JVM happens to handle the initalization of the object? Or, should I use a different approach to identify "this machine"?