not able to update jmx values of type- any primitive data type
rajajboss Dec 8, 2014 2:06 AMHi ,
I am trying to update the jmx values in jconsole as in the below program.I am able to update jmx attribute's value of type -wrapper type or any object type.
But I am not able to update jmx values of type -primitive data types.
I am getting exception when i am trying to the jmx attribute value of type boolean .please note that it is not java.lang.Boolean.
Code
public void modifyMBean(String beanName, Attribute editedAttribute) throws IntrospectionException, InstanceNotFoundException, ReflectionException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, IOException, MalformedObjectNameException {
Object bname=null;
try {
for(Entry<Object,Object> beanname :Config.getInstance().getProperties().entrySet()){
if(beanname.getValue().equals(beanName)){
bname = beanname.getKey();
}
}
} catch (Exception e) {
e.printStackTrace();
}
String host = "localhost";
int port = 9999;
String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;
System.out.println("\n\n\t**** urlString: "+urlString);;
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
ObjectName objectName = new ObjectName(bname.toString());
javax.management.Attribute changedAttributeValue = null;
try {
if(editedAttribute.getType().equals("java.lang.String")){
changedAttributeValue = new javax.management.Attribute(editedAttribute.getName(), editedAttribute.getValue());
connection.setAttribute(objectName,changedAttributeValue);
}
else if(editedAttribute.getType().equals("java.lang.Long")||editedAttribute.getType().equals("long")){
changedAttributeValue = new javax.management.Attribute(editedAttribute.getName(), new Long(editedAttribute.getValue()));
connection.setAttribute(objectName,changedAttributeValue);
}
else if(editedAttribute.getType().equals("java.lang.Boolean")||editedAttribute.getType().equals("boolean")){
changedAttributeValue = new javax.management.Attribute(editedAttribute.getName(), new Boolean(editedAttribute.getValue()));
connection.setAttribute(objectName,changedAttributeValue); //am getting exception here when setting boolean literal value to jconsole bean attribute
}
else if(editedAttribute.getType().equals("java.lang.Integer")||editedAttribute.getType().equals("integer")){
changedAttributeValue = new javax.management.Attribute(editedAttribute.getName(), new Integer(editedAttribute.getValue()));
connection.setAttribute(objectName,changedAttributeValue);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Error:
java.io.IOException: java.lang.ClassNotFoundException: No classloader available
at org.jboss.remotingjmx.protocol.v2.ServerProxy$SetAttributeHandler.handle(ServerProxy.java:1111)
at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1.run(ServerCommon.java:152)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: No classloader available
at org.jboss.marshalling.AbstractClassResolver.getClassLoaderChecked(AbstractClassResolver.java:91)
at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135)
at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:947)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1259)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:213)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:72)
at org.jboss.remotingjmx.protocol.v2.ServerProxy$SetAttributeHandler.handle(ServerProxy.java:1109)
... 4 more