MBean service object references
fred Aug 21, 2001 5:45 PM(cross-posted from jboss-user)
Correct me if I'm wrong, but I get the impression that JMX was not intended to provide a service object reference. The JMX spec is unclear about this, but MBean interaction appears to block every avenue to get past the arm's-length invocation and get at a direct object reference.
I understand the JMX motivation for distributed interaction, but some (most?) apps would prefer either a simple registrar local to a VM or a smart proxy a la Jini LUS. Unfortunately, that doesn't appear to be forthcoming from JMX, so we must each hand-roll our little hacks.
I implemented a registration protocol on top of an MBeanServer that records the service object reference with a service broker. The Service Loader MBean below appears to be a similar concept. There are several gotchas, e.g. setting a listener for new MBean notification.
Since jboss is active in the JMX group, does somebody out there have more insight as to whether there is or will be a conventional way to obtain a direct service object reference?
----- Original Message -----
From: "Lennart Petersson" <lennart.petersson@benefit.se>
To: <jboss-user@lists.sourceforge.net>
Sent: Monday, August 20, 2001 11:40 PM
Subject: SV: [JBoss-user] How to obtain the reference of a MBean?
Here is an snippet from my code:
/** Reference to a instance of the MbeanServer */
private transient MBeanServer mbeanServer = null;
/** ObjectName of the service loader MBean */
private transient ObjectName serviceLoader = null;
try
{
// Get instance to MBeanServer
Collection col = MBeanServerFactory.findMBeanServer(null);
if(col.isEmpty())
{
System.out.println("No MBeanServer found");
return;
}
// Assumes there is only one :-)
mbeanServer = (MBeanServer)col.iterator().next();
// Construct ObjectName of the service loader MBean (this is our own MBean)
Set set = mbeanServer.queryMBeans(new ObjectName("*:service=ECS Service Loader"), null);
if(set.isEmpty())
{
System.out.println("No ECS Service Loader MBean found");
return;
}
// Now i know that there is only one :-)
serviceLoader = ((ObjectInstance)set.iterator().next()).getObjectName();
}
catch(final Exception e)
{
System.out.println("Failed to create a trader bean");
e.printStackTrace();
}
// Now i have a ref to our ECS Service Loader MBean and can invoke methods on it like in this example:
try
{
// Get a collection of available services from our ECSServiceLoader MBean using the MBeanServer
return (Collection)mbeanServer.invoke(
serviceLoader,
"getServices",
new Object[0],
new String[0]);
}
catch(final Exception e)
{
System.out.println("Failed to get services from loader mbean");
e.printStackTrace();
return new ArrayList();
}
/Lennart
----- Original Message -----
From: Herve Tchepannou <htchepannou@objexis.com>
To: <jboss-user@lists.sourceforge.net>
Sent: Monday, August 20, 2001 9:02 PM
Subject: [JBoss-user] How to obtain the reference of a MBean?
> I've just successfuly deploy a MBean into JBoss.
> Im wondering how my EJB object can obtain the reference of the MBean object?
>