Two ways I know of:
1. Register with JNDI and look it up
2. Make it a singleton
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Frederick N.
Brier
Sent: Wednesday, September 19, 2001 8:30 AM
To: [EMAIL PROTECTED]
Subject: Re: SV: [JBoss-user] How to obtain the reference of a MBean?
First - Thank you all. I finally got the MBean notifications working with
my notifier. The last trick was to move the addListener code to the MBean
constructor from the startService(), because by the time my MBean got
started, the J2eeDeployer was already done. Now my next step is adding in
the functionality. The final code added to my MBean constructor is at the
end of this message.
My Misunderstanding:
--------------------------------
I did not realize that you have to invoke all operations of the MBean(s)
within an MBean server via the server object using an invoke() method. I
wasn't doing this. Since I was obtaining a reference to the MBean object
via JNDI, I had the actual object and was merely directly calling the
methods on the object. This was also why I was concerned about whether
calling an MBean, that played with threading or exec(), directly from an
EJB would cause problems. After getting the JNDI reference, you are just
making a function call. Does the MBean server, via the invoke method,
provide a thread dispatch type of layer of isolation? I haven't read the
MBean server code yet.
Potential Issue:
-----------------------
When I posted my code suggestion, I omitted adding the
NotificationBroadcaster interface to the J2eeDeployerMBean interface. The
way we added the feature to JBoss DOES work, but from a "spec" perspective,
does the NotificationBroadcaster interface have to exist in the MBean
interface, or is that only for setting properties and invoking functions?
Thank you again. And thank you Lennart for your example code. It clearly
points out the need not to assume there is only one MBean with the
specified name. David, thank you for pointing me at the test code. I
found the client test code in the 2.4.1 distribution which confused me
initially with all the invoke()s, but eventually brought enlightenment.
Fred.
--------------------------constructor code----------------------------------
try
{
MBeanServer server = (MBeanServer)
MBeanServerFactory.findMBeanServer(null).iterator().next();
ObjectName deployerObjName = new ObjectName(
J2eeDeployerMBean.OBJECT_NAME );
ObjectInstance deployerInst = server.getObjectInstance(
deployerObjName );
NotificationFilter notifyFilter = new NotificationFilter()
{
public boolean isNotificationEnabled( Notification
notification )
{
// We may want to filter on the phase as well
later.
return notification.getType().equals(
DeploymentNotification.TYPE_NOTIFICATION );
}
};
server.addNotificationListener( deployerObjName, this,
notifyFilter, null );
}
catch ( MalformedObjectNameException e )
{
}
catch ( InstanceNotFoundException e )
{
}
At 02:40 AM 8/21/2001, Lennart Petersson wrote:
>Here is an snippet from my code:
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user