Advertise with us

Our eBooks

JBoss cluster: discover cluster members

In this tutorial we will learn some techniquesto discover your JBoss AS cluster members using all the available instruments in JBoss AS 7: the mod_cluster API, the underlying JGroups transport, the embedded Infinispan cache manager or plain JMX API.

Discover cluster nodes with mod_cluster

The first (and most obvious) source of information about your cluster, when using AS 7, is mod_cluster. If you have installed the mod_cluster Manager:

<Location /mod_cluster-manager>
    SetHandler mod_cluster-manager

    Order deny,allow
    Deny from all
    Allow from

Then you can have a quick look at cluster members by requesting the mod_cluster-manager Web context:

mod cluster jboss as 7 discover cluster members

Note: You can use as well the CLI to achieve this information, using the list-proxies command on the modcluster's subsystem as shown here:

[standalone@localhost:9999 subsystem=modcluster] :list-proxies
    "outcome" => "success",
    "result" => [

Discover cluster nodes using JGroups

Another needful source of information is the underlying JGroups transport protocol. Since all members which join the cluster need to use a Channel object, then a simple and elegant solution to provide cluster members is reading the Channel's view which contains a getMembers method. Here's a sample code snippet:

        Channel channel = (Channel) CurrentServiceContainer.getServiceContainer().getService(ServiceName.JBOSS.append("jgroups", "channel", "web")).getValue();

        List<org.jgroups.Address> members = channel.getView().getMembers();
        List< IpAddress> addresses = new ArrayList< IpAddress>();

        for (org.jgroups.Address member: members) {
            PhysicalAddress physicalAddr = (PhysicalAddress)channel.down(new Event(Event.GET_PHYSICAL_ADDRESS, member));
            IpAddress ipAddr = ( IpAddress)physicalAddr;
            System.out.println("Found IP: "+ipAddr.getIpAddress().getHostAddress());

Discover cluster nodes using Infinispan

Infinispan is the default Cache Manager for JBoss AS 6 and JBoss AS 7. There's a simple shortcut into the EmbeddedCacheManager object which allows reading the cluster members:

       private CacheContainer container;

       . . . . . . 
        List<org.infinispan.remoting.transport.Address> members = container.getCache().getCacheManager().getMembers();

        for (org.infinispan.remoting.transport.Address member: members) {
            System.out.println("Found Member:" +member.toString());

Be Careful! Both Infinispan API and JGroups API use the Address class. We have fully specified the Class name in order to avoid conflicts between the imports!

Discover cluster nodes using JMX

If you are not satisfied with all the methods just shown, you can use plain old JMX to gather information about cluster nodes:

      Object obj = ManagementFactory.


                                        getAttribute(ObjectName.getInstance("jgroups:type=channel,cluster=\"web\""), "View");

© 2021 All Rights Reserved.

Please publish modules in offcanvas position.