Registering MBeans in a central MBeanServer

Discussion in 'Java' started by Sebastian, Apr 25, 2012.

  1. Sebastian

    Sebastian Guest

    Hello there,

    I'd like to register MBeans that are local to several applications -
    each running in their own JVM - in a central MBeanServer. An operation
    invocation on that registered bean (e. g. using a jconsole connected to
    the central server) should result in a remote callback (probably via
    RMI) to the local bean, which would be registered in its platform
    MBeanServer.

    In other words, instead of creating a local bean on the central server,
    I'd like to create a remote proxy to my application-local bean and
    register that, and I'd like the whole remoting stuff to be transparent.
    By that I mean I don't want to explicitly start RMI registries in each
    application, keep track of the ports in case they run on the same
    machine etc.

    There used to be (in the year 2005) a "JMXRemote" project on java net, cf.

    http://today.java.net/pub/a/today/2005/12/20/introduction-to-jmxremote.html

    but that seems defunct. This must be a common requirement, however, I
    haven't found anything useful with Google, nor in any of the JMX
    tutorials online.

    -- Sebastian
     
    Sebastian, Apr 25, 2012
    #1
    1. Advertising

  2. Sebastian

    Sebastian Guest

    Am 25.04.2012 15:38, schrieb Sebastian:
    > Hello there,
    >
    > I'd like to register MBeans that are local to several applications -
    > each running in their own JVM - in a central MBeanServer. An operation
    > invocation on that registered bean (e. g. using a jconsole connected to
    > the central server) should result in a remote callback (probably via
    > RMI) to the local bean, which would be registered in its platform
    > MBeanServer.
    >
    > In other words, instead of creating a local bean on the central server,
    > I'd like to create a remote proxy to my application-local bean and
    > register that

    [snip]

    I ascribe the lack of response to my not actually having asked a
    question. Meanwhile, I have implemented something, which has a
    surprising behavior. I'll describe the code in some detail below (and
    ask a question about it, too).

    Consider two JVMs, one "local" and one "central". The local JVM has an
    MBean server listening on port 7777 (defined by the system property
    com.sun.management.jmxremote.port=7777), the central one has port 6666.

    String localUrl = "service:jmx:rmi:///jndi/rmi://"
    + InetAddress.getLocalHost().getHostAddress() + ":7777"
    + "/jmxrmi";

    String remoteUrl = "service:jmx:rmi:///jndi/rmi://"
    + "centralServer:6666"
    + "/jmxrmi";

    On the local side, I simply register an MBean in the platform MBS:

    StandardMBean mbean = new StandardMBean( this,
    ComponentController.class, false );
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbs.registerMBean( mbean, oname() );

    When I connect with JConsole to port 7777 and call one of the operations
    exposed by ComponentController, evertyhing works as expected.

    Things start going wrong when I create a bean on the central server.
    That bean gets passed the service URL for my local MBS and the local
    bean's object name. Here's the code on the local side:

    JMXServiceURL centralUrl = new JMXServiceURL( remoteUrl );
    JMXConnector connector = JMXConnectorFactory.connect( centralUrl );
    MBeanServerConnection conn = connector.getMBeanServerConnection();
    conn.createMBean(
    "com.test.ComponentControllerCallback",
    oname(),
    new Object[] { localUrl, oname() },
    new String[] { "java.lang.String", "javax.management.ObjectName" } )

    The methods in ComponentControllerCallback (which also implements
    ComponentController) are supposed to use that information to obtain the
    necessary connection to my local bean and call it back.

    The very strange thing is that the simple presence of the above code to
    create an MBean on a different JVM wreaks havoc with my local MBS. That
    is, even if I connect again directly to the MBS on port 7777 (bypassing
    the central server), the methods that worked before will now throw
    ClassNotFoundExceptions for RMI-based classes. Deleting the above code
    snippet will restore correct behavior.

    Unfortunately, the class loading behavior of my application is too
    complicated to reproduce or describe briefly. It is a composite
    application developed with the SCA implementation of Apache Tuscany.

    But anyway: Does anyone have any idea what it is about JMX and the above
    code that could possibly throw the remote classloading mechanism into
    disarray?

    I did try reversing the order of local bean registration and remote bean
    creation, but to no avail. Could it be the fact that both JVMs run on
    the same host? I'm stumped. Perhaps there is an entirely different and
    better way to implement my requirement?

    -- Sebastian
     
    Sebastian, Apr 30, 2012
    #2
    1. Advertising

  3. On 12-04-30 11:05 AM, Sebastian wrote:
    > Am 25.04.2012 15:38, schrieb Sebastian:
    >> Hello there,
    >>
    >> I'd like to register MBeans that are local to several applications -
    >> each running in their own JVM - in a central MBeanServer. An operation
    >> invocation on that registered bean (e. g. using a jconsole connected to
    >> the central server) should result in a remote callback (probably via
    >> RMI) to the local bean, which would be registered in its platform
    >> MBeanServer.
    >>
    >> In other words, instead of creating a local bean on the central server,
    >> I'd like to create a remote proxy to my application-local bean and
    >> register that

    > [snip]
    >
    > I ascribe the lack of response to my not actually having asked a
    > question. Meanwhile, I have implemented something, which has a
    > surprising behavior. I'll describe the code in some detail below (and
    > ask a question about it, too).

    [ SNIP ]

    Well, no, I saw a question in the first post. :) I use JMX a lot and so
    it was an interesting problem.

    I verified that there are commercial offerings that do this: e.g. Oracle
    Coherence.

    I'm also thinking that Open DMK with its Cascading (see
    http://docs.oracle.com/cd/E19698-01/816-7607/components-35/index.html)
    does what you want.

    I'll play with your code snippets some, it's interesting stuff.

    AHS
    --
    A fly was very close to being called a "land," cause that's what they do
    half the time.
    -- Mitch Hedberg
     
    Arved Sandstrom, May 1, 2012
    #3
  4. Sebastian

    Guest

    Hi
    Im also stuck with a problem of registering the mbeans in central mbeanserver.however i think that my problem is not too complex.
    Earlier i used to use my local mbeanserver, and thus used registermbean to register my object, but now i have to use creatembean, which uses classnameas a parameter.now im trying to save an array in my mbean object, but as it is accepting class name as its parameter the array wont show up on jconsole. Plz Help.
     
    , Jul 5, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jajoo

    get MBeanServer remotly

    jajoo, Nov 23, 2004, in forum: Java
    Replies:
    0
    Views:
    483
    jajoo
    Nov 23, 2004
  2. Replies:
    1
    Views:
    6,932
  3. John
    Replies:
    0
    Views:
    368
  4. John
    Replies:
    0
    Views:
    673
  5. Juan T. Llibre
    Replies:
    2
    Views:
    3,987
    =?Utf-8?B?UmljaA==?=
    Dec 16, 2006
Loading...

Share This Page