Search code examples
javajakarta-eejmxjconsolembeans

Some of the methods in Mbean do not show in Jconsole?


Im having a simple Mbean which implements these interface

public interface HelloMBean {

    public void print();

    public void printHello();


    public int getInt();

    public String getName();
    public void setName(String s);

}

the implementation is:

public class Hello implements HelloMBean{

    private String name;

    @Override
    public String getName() {
        // TODO Auto-generated method stub
        return this.name;
    }

    @Override
    public void setName(String s) {
        // TODO Auto-generated method stub
        this.name=s;
    }

    @Override
    public void print() {
        // TODO Auto-generated method stub

        System.out.println("heelp!");

    }

    @Override
    public void printHello() {
        // TODO Auto-generated method stub

        System.out.println("heelp!"+" "+this.name);


    }

    @Override
    public int getInt() {
        // TODO Auto-generated method stub
        return 0;
    }

}

and I start to register my Mbean with Mbean Server,

MBeanServer server=ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName=new ObjectName("richard:name=fuck");

        try {
            server.registerMBean(new Hello(),objectName);
        } catch (InstanceAlreadyExistsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MBeanRegistrationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NotCompliantMBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            System.in.read();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

However when I check the Jconsole, it only has two operations which are print() and printHello

enter image description here

I dont know why is it happening since its just a very simple Mbean...


Solution

  • The rule is that get*() and set*() are (turned into) property accessors. Those are thus exposed under the attributes section and not in the operations.

    If a getter is present, the property can be read by JMX-clients, if a setter is present, then it can be written. It is perfectly valid to have setters only or getters only on such a property.