4 Replies Latest reply on Mar 14, 2007 1:23 PM by Brian Stansberry

    get partition(cluster)

    Oleg Ruchovets Newbie

      Hi , I try to get partition(cluster) name using external applicatin using JMX.

      String jmxQuery = "jboss:service=DistributedReplicantManager,*";
      // getting the server MBean


      Set set = connection.queryNames(new ObjectName(jmxQuery), null);

      if (set != null && set.size() > 0) { // this is a cluster
      for (Iterator i = set.iterator(); i.hasNext();) {
      ObjectName on = (ObjectName) i.next();
      System.out.println("--"+on);
      String ClusterName = on.getKeyProperty("partitionName");
      }
      }

      Is it correct way to get a cluster name using DistributedReplicantManager.
      and may be you have a reference how to discover a full topology of jboss (all partitions , clusters and servers in it).
      Thanks in Advance Oleg

        • 1. Re: get partition(cluster)
          Jerry Gauthier Apprentice

          I'm not clear on whether you're trying to access the DistributedReplicantManager service remotely or if you're looking for something else. Here's an example of how to use the DRM service remotely in JBoss 4.0.5. Note that your remote client will need various JBoss jars on its classpath. You'll get runtime errors on your client until the classpath is set properly.

          // method 1 - using JBoss RMIAdaptor
          //RMIAdaptor server1 = (RMIAdaptor)ic.lookup("jmx/invoker/RMIAdaptor");
          //System.out.println("MBean count=" + server1.getMBeanCount());

          // method 2 - using javax.management in JDK 1.5, same object type is returned in JBossAS
          MBeanServerConnection server2 = (MBeanServerConnection)ic.lookup("jmx/invoker/RMIAdaptor");
          System.out.println("MBean count=" + server2.getMBeanCount());

          ObjectName clusterService = new ObjectName("jboss:partitionName=DefaultPartition,service=DistributedReplicantManager");
          String drm_content = (String)server2.invoke(clusterService, "listContent", null, null);
          System.out.println(drm_content);

          • 2. Re: get partition(cluster)
            Jerry Gauthier Apprentice

            Sorry - I neglected to point out that this example uses JNDI to initially access the mbean server. You'll need to configure an initial context to access the server.

            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL, "jnp://localhost: 1099");
            env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

            Context ic = new InitialContext(env);

            • 3. Re: get partition(cluster)
              Oleg Ruchovets Newbie

              Thank you for your answer. Aclually I have no problem to connect to the server and use DistributedReplicantManager. I have only jbossall-client.jar and it's enough. the question is :
              Is it a correct way to get cluster(partition) names , and may be someone already faced with this problem and can give a good reference or code example how to discover jboss topology (clusters , servers).
              Regards Oleg

              • 4. Re: get partition(cluster)
                Brian Stansberry Master

                I haven't looked at it carefully, but what you wrote seems valid. FYI, here's how org.jboss.ha.jmx.HAServiceMBeanSupport finds its partition. I know this query works and finds the partition. This could be modified to exclude matching on an expected partition name, etc.

                 protected HAPartition findHAPartitionWithName(String name) throws Exception
                 {
                 log.debug("findHAPartitionWithName, name="+name);
                 HAPartition result = null;
                 QueryExp classEQ = Query.eq(Query.classattr(),
                 Query.value(ClusterPartition.class.getName()));
                 QueryExp matchPartitionName = Query.match(Query.attr("PartitionName"),
                 Query.value(name));
                 QueryExp exp = Query.and(classEQ, matchPartitionName);
                 Set mbeans = this.getServer().queryMBeans(null, exp);
                 if (mbeans != null && mbeans.size() > 0)
                 {
                 ObjectInstance inst = (ObjectInstance) (mbeans.iterator().next());
                 ClusterPartitionMBean cp =
                 (ClusterPartitionMBean) MBeanProxyExt.create(
                 ClusterPartitionMBean.class,
                 inst.getObjectName(),
                 this.getServer());
                 result = cp.getHAPartition();
                 }
                
                 if( result == null )
                 {
                 String msg = "Failed to find HAPartition with PartitionName="+name;
                 throw new InstanceNotFoundException(msg);
                 }
                 return result;
                 }


                There's no general facility that lists all the deployed partitions; the JMX query approach is what you have to do.