-
1. Re: get partition(cluster)
jerrygauth Mar 13, 2007 4:04 PM (in response to oruchovets)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)
jerrygauth Mar 13, 2007 4:07 PM (in response to oruchovets)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)
oruchovets Mar 14, 2007 6:12 AM (in response to oruchovets)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 Mar 14, 2007 1:23 PM (in response to oruchovets)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.