This discussion is archived
5 Replies Latest reply: Feb 28, 2012 12:52 AM by jorgemoralespou RSS

MBeanServer location in JNDI tree

919262 Newbie
Currently Being Moderated
Hello,

I'm testing methods that use a MBeanServer from JConsole and MBean browser in EM console. I launch the JConsole using this parameters:

jconsole -J-Djava.class.path=/home/user/wlfullclient-10.3.5.0.jar:/usr/java/jdk1.6.0_30/lib/jconsole.jar -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote

When I use the JConsole for testing I obtain the MBeanServer in this way:

InitialContext ctx = new InitialContext();
server = (MBeanServer)ctx.lookup("java:comp/jmx/runtime");

And when I use the MBean browser I have to to use this code:
server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");


I'm following the next Oracle documentation, but I want to know if there is other way to use only once String to found the MBeanServer in the JNDI tree.

Does anybody know a different way to do this?

Thanks in advance,

Make Local Connections to the Runtime MBean Server+

Local clients can access a WebLogic Server instance’s Runtime MBean Server through the JNDI tree instead of constructing a JMXServiceURL object. Only the Runtime MBean Server registers itself in the JNDI tree.+

When accessed from JNDI, the Runtime MBean Server returns its javax.management.MBeanServer interface. This interface contains all of the methods in the MBeanServerConnection interface plus additional methods such as registerMBean(), which local process can use to register custom MBeans. (See MBeanServer in the J2SE 5.0 API Specification.)+

If the classes for the JMX client are located at the top level of an enterprise application (that is, if they are deployed from the application’s APP-INF directory), then the JNDI name for the Runtime MBean Server is:+

java:comp/jmx/runtime


If the classes for the JMX client are located in a Java EE module, such as an EJB or Web application, then the JNDI name for the Runtime MBeanServer is:+

java:comp/env/jmx/runtime



For example:

InitialContext ctx = new InitialContext();

server = (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");
  • 1. Re: MBeanServer location in JNDI tree
    EJP Guru
    Currently Being Moderated
    I want to know if there is other way
    Why? What's wrong with the way you quoted?
  • 2. Re: MBeanServer location in JNDI tree
    919262 Newbie
    Currently Being Moderated
    Hi,

    Nothing is wrong, but I prefer to not catch the exception and then try to obtain the MBeanServer with the other String. Is not there an unique String to locate the object?

    Thanks,
  • 3. Re: MBeanServer location in JNDI tree
    EJP Guru
    Currently Being Moderated
    Two different deployments, two different JNDI names, exactly as documented. There's nothing there that suggests there is a single name that will work for both.
  • 4. Re: MBeanServer location in JNDI tree
    jorgemoralespou Newbie
    Currently Being Moderated
    Hi,
    I have same problem.
    I have developed some libs (with common functionality to be used in many places, utils, and so) which I deploy in $DOMAIN/lib. I also have an ear, with ApplicationLifecycleListener to register some MBeans in the MBeanServer and they make use of this shared libs.
    The thing is that if I access on of my MBeans from JConsole and if I access the same MBean from within em console, my app needs to look at different locations in the JNDI tree for the MBeanServer. Shouldn't this code, as it is running in the same location need to locate the MBeanServer the same way? Or because the client application in one case is remote, and in the other is local, need to look for the MBeanServer in one location and if not found in the other.
    Think that code is deployed as a Util class in the DOMAIN/lib directory.

    Thanks,
  • 5. Re: MBeanServer location in JNDI tree
    EJP Guru
    Currently Being Moderated
    Shouldn't this code, as it is running in the same location need to locate the MBeanServer the same way?
    It should behave as it is documented to behave. It seems to me that it is doing that. Your question?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points