-
1. Re: Recommended way for MBean A to call MBean b
genman Oct 16, 2003 3:49 PM (in response to paulmoore100)
I usually include an attribute (Instance) and create a getInstance MBean method. Have it return "this". For looser coupling, create an interface with the methods you want to expose.
The JBoss folk seem to follow this approach.
You can also have one mbean construct the other, and you can hold a reference in the first. (Method "registerMBean".)
http://java.sun.com/j2ee/1.4/docs/api/javax/management/MBeanServer.html#registerMBean(java.lang.Object,%20javax.management.ObjectName) -
2. Re: Recommended way for MBean A to call MBean b
andygodwin Oct 17, 2003 6:29 PM (in response to paulmoore100)Paul
You could use org.jboss.mx.util.MBeanProxy which gives you a
dynamic proxy based instance of the MBean so that you can call the
MBean methods directly on the proxy object.
For example, if you have an MBean, say MyService, that implements
MyServiceMBean and is registered with an MBean ObjectName of, say,
foo:service=MyService then any other MBean can get a reference
to this MBean and call methods on it as follows:
ObjectName fooName = new ObjectName("foo:service=MyService");
MyServiceMBean myServiceMBean =
(MyServiceMbean)MBeanProxy.get(MyServiceMBean.class,
fooName, server);
myServiceMBean.someMethod();
The dynamic proxy completely hides the MBeanServer invocation so that
you can use it as if it were an instance of the MBean object.
FWIW, there is no "official JMX" way to do this ... one of the points of
the MBeanServer invoke() method is that the invoker doesn't have to have
a reference to the java.lang.Class of the object that it's invoking methods
on ... this avoids lots of problems with ClassLoaders and redeployment.
Also, genman's comments about using interfaces is wise, especially if you
want to be able to redeploy one MBean whilst leaving the other one running!
HTH
Andy -
3. Re: Recommended way for MBean A to call MBean b
juha Oct 19, 2003 7:18 AM (in response to paulmoore100)You will not find an "official" way to do this in the JMX spec as the main purpose of the architecture and JMX API design is to hide the actual component references to force a loosely coupled in VM relationships.
-- Juha