Are JMX CompositeDataSupport attributes always read-only in JConsole?

2.1k Views Asked by At

Following MXBeans in Java SE 6: Bundling Values Without Special JMX Client Configurations I managed to implement a MXBean which exposes a Map<String, String> for a list of configuration parameters. It appears in JConsole as expected, but all values are readonly.

In the MXBEans article, this illustration shows an example where it makes sense that the attributes are read-only as they are memory usage values.

enter image description here

Is there a way to make the attributes editable in JConsole?

3

There are 3 best solutions below

0
On

To make attributes writable from JConsole, you need to expose the setter methods also in your MBean Interface.

package com.example; 
public interface HelloMBean { 

public void sayHello(); 
public int add(int x, int y); 

public String getName(); 

public int getCacheSize(); 
public void setCacheSize(int size); 

}

In this name is readOnly, cacheSize is read as well as write enabled.

0
On

Try using Spring MBeanExporter.
I am not sure, if this is feasible with you or not.
But it is very easy. Here is a very good example.

Thanks.

0
On

I don't think you can make the individual elements writable (think about it from a remote API perspective, the compound type is simply a DTO, the mbean is the remote interface), but i do think you can make the whole compound attribute writable, e.g.:

public Map<String,String> getConfig() {}

public void setConfig(Map<String,String> newConfig) {}

that said, i'm not sure if jconsole supports editing compound attributes even if they are writable.