5 Replies Latest reply on Apr 29, 2003 11:25 PM by stevecoh1

    Accessing an MBean from within JVM

    stevecoh1 Newbie

      Dumb newby question.

      How do I access an MBean and its methods via code, from within the same JVM?

      The documents treat this as a question too trivial to be discussed but how DO you access a Standard MBean and its methods from within code?

      I can see where I can get to the setAttribute() and getAttribute() methods through the server, but then I look at the implementation in the source code and I see that your code is expecting the beans it gets from the server to be Dynamic MBeans, so that won't work. I don't see a method in the MBeanServer to get the MBean itself so I can't do that and then call its methods directly.

      Here's what I want to do (oversimplified)

      MyBean mybean = (MyBean)server.getMBean(ObjectName)

      int num = myBean.getNum()
      num = num + 1;
      myBean.setNum(num);

      I know I can't do that, but what is the right way to do it?

      I know I'm missing something simple but I don't know what it is.