Discover cluster nodes using Probe shell script

Another discovery tool which shipped with JBoss AS 4-5-6 is the probe.sh shell which invokes a test class contained in JGroups API named org.jgroups.tests.Probe.

This class sends a multicasts a packet to 224.0.75.75:7500 (default multicast address and port) and waits for responses until the timeout has elapsed. Here's how you can adapt it to JBoss AS 7 (warning not tested!)

 

 

set CLASSPATH=%JBOSS_HOME%\modules\org\jgroups\main\jgroups-3.0.6.Final.jar

set CP=%CLASSPATH%

java -cp %CP% org.jgroups.tests.Probe %*

Here's the expected output:

-- send probe on /224.0.75.75:7500

#1 (263 bytes): 192.168.0.1:2222 (ClusterGroup)
local_addr=192.168.0.1:2222
group_name=ClusterGroup
Version=2.2.9 beta, cvs="$Id: Version.java,v 1.23 2006/04/04 17:21:24 
p $"
view: [192.168.0.1:2222|1] [192.168.0.2:2222:2226|1]
group_addr=226.6.6.6:12345
. . . . . . .
Finally, if you want a Quick Servlet for dumping the various programming options displayed in this tutorial:


package com.sample;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.infinispan.manager.CacheContainer;
import org.infinispan.remoting.transport.Address;
import org.infinispan.remoting.transport.jgroups.JGroupsAddress;
import org.jboss.as.server.CurrentServiceContainer;
import org.jboss.msc.service.ServiceName;

import org.jgroups.Channel;
import org.jgroups.Event;
import org.jgroups.PhysicalAddress;
import org.jgroups.stack.IpAddress;

import java.util.Hashtable;
import javax.management.*;
import javax.management.remote.*;


/**
 * Servlet implementation class TestCluster
 */
@WebServlet("/TestCluster")
public class TestCluster extends HttpServlet {
    private static final long serialVersionUID = 1L;
    @Resource(lookup="java:jboss/infinispan/container/cluster")
    private CacheContainer container;


    public TestCluster() {
        super();
        // TODO Auto-generated constructor stub
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //getClusterMembersInfinispan();
        try {
            getClusterMembersJGroups(response);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public Collection<IpAddress> getClusterMembersJGroups(HttpServletResponse response) {
        PrintWriter out = response.getWriter();
        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;
            out.println("Found IP: "+ipAddr.getIpAddress().getHostAddress());
            addresses.add(ipAddr);
        }
        out.close();
        return addresses;
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }
    public Collection<org.infinispan.remoting.transport.Address> getClusterMembersInfinispan(HttpServletResponse response) {
        PrintWriter out = response.getWriter();
        List<org.infinispan.remoting.transport.Address> members = container.getCache().getCacheManager().getMembers();
        for (org.infinispan.remoting.transport.Address member: members) {
            out.println("Found Member:" +member.toString());
        }
        out.close();
        return members;
    }

    public void getClusterMembersJMX(HttpServletResponse response) throws Exception {
        PrintWriter out = response.getWriter();
        Object obj = ManagementFactory.getPlatformMBeanServer().getAttribute(ObjectName.getInstance("jgroups:type=channel,cluster=\"web\""), "View");
        out.println(obj);
        out.close();
    }
}  

Just keep in mind that when deploying your Servlet, you need to trigger some dependencies like the JBoss AS core modules, the Infinispan API and JGroups API.

Dependencies: org.jboss.as.server,org.jgroups,org.infinispan export                         
0
0
0
s2smodern

Related articles available on mastertheboss.com

JBoss Clustering a Web Application

Please Note: This article cover JBoss AS 4/5/6 releases. If you w

Clustering EJB 3 with JBoss AS

To cluster a stateless session bean in EJB 3 all you need to do i

JBoss monitoring HTTP Session replication

In this article we'll show how to monitor HTTPSession replication

How do I change multicast address of JBoss cluster ?

Since JBoss AS 4.0.3, the jboss.partition.udpGroup property can b

JBoss farming service

What is the farming service ? this article explains about it, als

JBoss HTTP Session replication

HTTP session replication is used to replicate the state associate