JBoss Clustering - How Many Nodes In The Cluster?

Author: Alexander Zagniotov
Category: Software RSS
Republish this article manually
Republish articles from Software category automatically

If you want to know how many nodes there are in the current cluster partition, all you have to do is to ask HAPartition for the node list. HAPartition represents your cluster partition, and it contains all the information you need to know about your cluster and the nodes: their host names, IPs, position in the cluster view.

Lets assume you have a service bean that extends from HASingletonSupport. HASingletonSupport in its turn extends from HAServiceMBeanSupport.

HAServiceMBeanSupport is the one who gives you access to HAPartition object.

The code to request for HAPartition object and node list that you see below , you can put somewhere in your service bean:


HAPartition partition = getPartition();ClusterNode[] nodes = partition.getClusterNodes();System.out.println(nodes.length);

ClusterNode object represents your node in the cluster. It contains information about node's host name, its internet address and a few more things. getClusterNodes(), returns to you an array contains as many ClusterNode objects as you have currently in your cluster. So by getting the value of array length, you will know how many nodes your cluster has.

Another way, is to do practically the same, but to request from a HAPartition a current view of your cluster:


HAPartition partition = getPartition();Vector v = partition.getCurrentView();System.out.println(partition.getCurrentView().size());for (Object o : v) {

System.out.println(o.toString());}

The view, which is a Vector contains information about node sockets. When printed, it will return to you a String representation of node ip port: xxx.xxx.xxx.xxx:port. Also by printing size of the Vector, you will get number of nodes in the cluster.

Important note:

I noticed there is some delay happening from the time when node leaves the cluster to the time when HAPartition returns updated view. In another words - after node has left the cluster and topology change occurred, the HAPartition may return to you an old view still containing the dead node. So be careful.

Thats it.

Resource Box:
Original Article URL: JBoss Clustering - How Many Nodes In The Cluster?

Alexander Zagniotov resides in Melbourne, Australia. He has recently graduated from Victoria University in Melbourne with BSc in Computer Science. In his blog Java Beans dot Asia Alexander writes about interesting and new things he encounters as J2EE developer.


Keywords: java, programming, jboss, clustering, j2ee
View Count: 59
Date Submitted: 5/29/2008

Most recent articles in Software category:



Other related articles in Software category: