You can get this info programatically by querying the JMX MBean server. You will need to query the MBean jboss:partition=DefaultPartition,service=HAPartition
and look for the value of the attribute CurrentView
. The CurrentView
will provide the current nodes in the cluster along with their host/IP address. You can also verify this data by matching it up against the data from the jmx-console
for the same MBean.
You can put this logic inside an EJB. One catch you need to be aware of is that you do not want your EJB to be deployed before the clustering service has been deployed and started. Otherwise your EJB might throw exceptions (eg. InstanceNotFoundException
). Therefore, add a depends
clause for the clustering MBean (jboss:service=DefaultPartition
) in your jboss-web.xml
for your EJB deployment package.