0

I have simple MBean X with 3 methods and four attributes. It implements interface XMBean (2 methods).

In other class I register it:

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    X x= new X(14, 16, 17, 13);

    ObjectName name = new ObjectName("package:type=xxxx");

    mbs.registerMBean(x, name);

I can see it in jConsole. I can call two methods that I implements from interface. I think I should see also attributes of my MBean? Why jConsole shows me only operations? How to show attributes?

peter55555
  • 1,413
  • 1
  • 19
  • 36

2 Answers2

0

I've pasted simple code below:

public class X implements XMBean
{
    public Automat(int aa, int bb, int cc, int dd)
    {
        a = aa;
        b = bb;
        c = cc;
        d = dd;
    }

    public int operation1(char product)
    {
        return 1;
    }

    public int operation2(char product)
    {
        return 2;
    }

    public Integer getA()
    {
        return a;
    }

    public Integer getB()
    {
        return b;
    }

    public Integer getC()
    {
        return c;
    }

    public Integer getD()
    {
        return d;
    }

    private int a;
    private int b;
    private int c;
    private int d;
}

////////////////////////////////////////////////////////////////////////////////////////

public interface XMBean
{
    public int operation1(char product);
    public int operation2(char product);
}
peter55555
  • 1,413
  • 1
  • 19
  • 36
  • 1
    I see two things missing - the interface does not have getter setters while the implementation class does not have setters too. Have a look at this example - http://examples.javacodegeeks.com/enterprise-java/jmx/create-and-register-mbean-in-mbeanserver/ – Andy Dufresne Dec 21 '14 at 11:43
0

JMX relies heavily on reflection using the *MBean interfaces. As Andy says, the XBean Interface has to expose the attributes in getter and/or setter. From the Oracle's JMX tutorial:

As defined by the JMX specification, a getter is any public method that does not return void and whose name begins with get. A getter enables a manager to read the value of the attribute, whose type is that of the returned object. A setter is any public method that takes a single parameter and whose name begins with set. A setter enables a manager to write a new value in the attribute, whose type is the same as that of the parameter.

If you're using Eclipse, you can easily generate the Interface by right-clicking to open the context menu and clicking on Refactor > Extract Interface.