4 Replies Latest reply on Jan 18, 2016 4:27 PM by sumanthreddybandi

    NotificationBroadcasterSupport to a clustered environment in wildfly

    sumanthreddybandi

      I have nodefinder service(*-service.xml) in jboss-4.2.3.   We used to have org.jboss.ha.jmx.HAServiceMBeanSupport class to provide "NotificationBroadcasterSupport to a clustered environment" in jboss 4.2.3

       

      This is my "nodefinder-service.xml"

       

      <?xml version="1.0" encoding="UTF-8"?>

      <server>

          <mbean code="com.test.mbeanservice.NodeFinder" name="jboss:service=NodeFinder">

               <attribute name="PartitionName">TestPilot_123</attribute>

          </mbean>

      </server>

       

      NodeFinder.java

       

      import java.util.ArrayList;

      import java.util.List;

      import java.util.Vector;

      import org.jboss.ha.framework.interfaces.HAPartition;

      import org.jboss.ha.jmx.HAServiceMBeanSupport;

      public class NodeFinder extends HAServiceMBeanSupport implements NodeFinderMBean {

             @Override

             public List<String> getNodes() {

                            List<String> nodes = new ArrayList<String>();

                            HAPartition partition;

                            try {

                                 partition = getPartition();

                                 Vector v = partition.getCurrentView();

                                 for (Object o : v) {

                                        nodes.add(o.toString());

                                 }

                                 return nodes;

                            } catch (Exception e) {

                                 //log error

                            }

             }

      }

       

      NodeFinderMBean.java

       

      public interface NodeFinderMBean extends HAServiceMBean{

           public List<String> getNodes();

      }

       

      But deployment of nodefinder service is failing now because HAServiceMBeanSupport is not supported in Wildfly. How can we achieve the same in wildfly?

        • 1. Re: NotificationBroadcasterSupport to a clustered environment in wildfly
          pferraro

          The equivalent would be something like this:


          @Resource(lookup = "java:jboss/clustering/group/default")
          private org.wildfly.clustering.group.Group group;
          
          public List<String> getNodes() {
             return this.group.getNodes().stream().map(node -> node.getName()).collect(Collectors.toList());
          }
          

           

          Where "default" is an alias to the default JGroups channel of the server.

          • 2. Re: NotificationBroadcasterSupport to a clustered environment in wildfly
            sumanthreddybandi

            Getting a NPE when i use the above code. i used "java:jboss/clustering/group/default" as well as ""java:jboss/clustering/group/ejb"

            In both cases, group object is NULL.

             

            Currrently i have only one node(node1). And in the logs, i am seeing the channel as 'ejb'

             

            INFO   [org.infinispan.remoting.transport.jgroups.JGroupsTransport:186] (ServerService Thread Pool -- 73) ISPN000078: Starting JGroups channel ejb

            INFO   [org.infinispan.remoting.transport.jgroups.JGroupsTransport:785] (ServerService Thread Pool -- 73) ISPN000094: Received new cluster view for channel ejb: [node1|0] (1) [node1]

            INFO   [org.infinispan.remoting.transport.jgroups.JGroupsTransport:224] (ServerService Thread Pool -- 73) ISPN000079: Channel ejb local address is node1, physical addresses are [xx.xx.xx.xx:xxx]

             

            Am i missing anything here?

            • 3. Re: NotificationBroadcasterSupport to a clustered environment in wildfly
              pferraro

              It seems that when CDI is used to resolve @Resource annotations (as opposed to WF's ee subsystem), it fails to establish the appropriate dependencies required to start the Group service backing this.  You can work around this by using a resource-ref in your deployment descriptor and reference the Group using an application-specific namespace.

              e.g.

              <resource-ref>
                <res-ref-name>group/default</res-ref-name>
                <lookup-name>java:jboss/clustering/group/default</lookup-name>
              </resource-ref>
              

               

              @Resource(name = "group/default")
              private Group group;
              
              • 4. Re: NotificationBroadcasterSupport to a clustered environment in wildfly
                sumanthreddybandi

                Still getting group as Null. But i am able to see the list of nodes with below code:

                ObjectName name = null;
                MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                try {
                name = new ObjectName("jboss.infinispan:type=CacheManager,name=\"ejb\",component=CacheManager");
                String clusterMembers = (String) (server.getAttribute(name, "clusterMembers"));
                log.info("Cluster Members: "+clusterMembers);
                } catch (Exception e) {
                e.printStackTrace();
                }
                
                

                In the logs:

                [org.infinispan.remoting.transport.jgroups.JGroupsTransport:785] (ServerService Thread Pool -- 68) ISPN000094: Received new cluster view for channel ejb: [node2|1] (2) [node2, node1]

                Cluster Members: [node2, node1]

                 

                Why am i not able to see cluster members with the JGroups channel?