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 an updated view. In another words – after node has left the cluster and topology change has occurred, the HAPartition may return to you an old view still containing the dead node. So be careful.
Also, getPartition() may return null, if super.startService() hasnt been called. Have a look at implementation of HAServiceMBeanSupport and my other post JBoss Clustering – HASingleton service.
Thats it ![]()
loading...
Related posts:
- JBoss Clustering – Shared State Across Cluster Partition
Did you know that if you have a JBoss cluster, HA singletons service beans on each can share a common memory state? State... - JBoss Clustering Architecture – Distributed Replicant Manager
My understanding of Distributed Replicant Manager (DRM) is that it allows you to attach some serialized data (stub) to a cluster node and... - JBoss Clustering – HASingleton Service
Have you ever dealt with clustered singleton service? How to determine which cluster node is the master? Well, if I am the current... - Deployment of MBean Separately to Its Interface
Few days ago i came across a little nasty thing during mbean deployment. What I did was separation of my mbean class and... - Using Template to Deploy a JBoss Queue
Currently I am involved in a project, where I have to use Velocity template engine to deploy queues and message-driven beans to JBoss....
