Reputation: 813
I'm using Glassfish clustering with 4 machines.
I'm also using remote EJB in order to call a method to this cluster. When I'm calling the method, one of these four machines processes it. I would like to know which one. So I create a remote EJB to get the identifier of the machine. With this, I can know which machine is processing my request. Problem is how can I assign an ID for each machine?
Upvotes: 0
Views: 87
Reputation: 813
This is a better solution that displays the pid of the process with the hostname of the machine
ManagementFactory.getRuntimeMXBean().getName();
By example: 958@my-machine
Edit: As jgitter, this is not a better solution. Just another solution. Sorry.
Upvotes: 1
Reputation: 3414
How about using the host name or IP of the machine itself?
InetAddress.getLocalHost().getHostName();
InetAddress.getLocalHost().getAddress();
http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html
Note: If the machines in question have multiple network interfaces, I don't think there is any guarantee which interface is returned via these methods.
Upvotes: 1