This constructor is for the case when you know the agent id. There
used to be a case where we created an MBeanServer and then referenced
it later. In that case, we knew the agent id, so to guarantee that
we got the same mbean server, I wrote this code.
I'm not sure it is used anymore. In any case, you could add a no arg
constructor that finds the mbean server as you have coded.
-dain
On Jun 27, 2007, at 5:05 AM, Vamsavardhana Reddy wrote:
I see the following constructor:
public RealMBeanServerReference(String mbeanServerId) throws
MBeanServerNotFound {
ArrayList servers = MBeanServerFactory.findMBeanServer
(mbeanServerId);
if ( servers.size() == 0) {
mbeanServer = MBeanServerFactory.createMBeanServer
("geronimo");
} else if (servers.size() > 1) {
throw new MBeanServerNotFound(servers.size() + "
MBeanServers were found with the agent id " + mbeanServerId);
} else {
mbeanServer = (MBeanServer) servers.get(0);
}
}
I guess the intention of this code is to use a single MBeanServer
for all geronimo MBeans and the default domain for that MBeanServer
be "geronimo". MBeanServerFactory.createMBeanServer() takes domain
as parameter. Whereas MBeanServerFactory.findMBeanServer() takes
AgentId. There is no (easy) way to create an MBeanServer with a
predefined agentId. Does this mean mbeanServerId parameter is
redundant? Should this code be searching for an MBeanServer with
default domain "geronimo" and creating one if there is none? In
this case, the code should look something like...
public RealMBeanServerReference(String mbeanServerId) throws
MBeanServerNotFound {
ArrayList servers = MBeanServerFactory.findMBeanServer(null);
for(int i = 0; i < servers.size(); ++i) {
if("geronimo".equals(((MBeanServer) servers.get
(i)).getDefaultDomain()))
mbeanServer = (MBeanServer) servers.get(i);
}
if(mbeanServer == null) mbeanServer =
MBeanServerFactory.createMBeanServer("geronimo");
}
I am also noticing that if I create a new JMX agent by specifiying
the system property com.sun.management.jmxremote.port, geronimo
hooks up to the MBeanServer created with default domain name
"DefaultDomain" instead of creating a new one for itself with
default domain "geronimo".
Vamsi