-
1. Re: code to update mbean attribute value thru programatically.
jaysensharma Nov 25, 2014 7:59 AM (in response to rajajboss)1 of 1 people found this helpfulAll the MBean attributes can not be written. However i have quickly written a simple example to demonstrates how you cah change the ROOT loggers logging level to TRACE using MBean code by setting Attribute "level" on MBean "jboss.as:subsystem=logging,root-logger=ROOT"
package client; import javax.management.*; import javax.management.remote.*; import javax.management.Attribute; public class JMXExample { public static void main(String[] args) throws Exception { 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("jboss.as:subsystem=logging,root-logger=ROOT"); String level = (String) connection.getAttribute(objectName,"level"); System.out.println("\n\tCurrent log level for ROOT logger is : " + level); System.out.println("\n\tTrying to set ROOT logger level as TRACE "); Attribute levelChange = new Attribute("level", "TRACE"); connection.setAttribute(objectName,levelChange); level = (String) connection.getAttribute(objectName,"level"); System.out.println("\n\tAfter Setting the Logger Level ROOT logger is : " + level); jmxConnector.close(); } }
Hope this will give some idea
-
2. Re: code to update mbean attribute value thru programatically.
rajajboss Nov 26, 2014 1:50 AM (in response to jaysensharma)Hi,
I am getting the below error when i am executing the above program.
Exception in thread "main" java.net.MalformedURLException: Unsupported protocol: remoting-jmx
at javax.management.remote.JMXConnectorFactory.newJMXConnector(Unknown Source)
at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
at com.alu.dsa.utils.Client.main(Client.java:14)
-
3. Re: code to update mbean attribute value thru programatically.
jaysensharma Nov 26, 2014 2:04 AM (in response to rajajboss)The "remoting-jmx" protocol support will be present inside the jboss client jar (Which can be found inside the $JBOSS_HOME/bin/client) so add that jar in your clients classpath before running this code.
-
4. Re: code to update mbean attribute value thru programatically.
rajajboss Nov 27, 2014 12:35 AM (in response to jaysensharma)Hi,
I am able to update the JMX attribute value programatically . But I need to update JMX attribute description also.Is this possible.
-
5. Re: code to update mbean attribute value thru programatically.
ctomc Nov 27, 2014 6:10 AM (in response to rajajboss)raja reddy wrote:
Hi,
I am able to update the JMX attribute value programatically . But I need to update JMX attribute description also.Is this possible.
what exactly do you have in mind by "description" ?
-
6. Re: code to update mbean attribute value thru programatically.
rajajboss Nov 27, 2014 7:45 AM (in response to rajajboss)Hi,
what I mean is --- I want to change the XXX datasource's maxpoolsize description through programatically.
How to achieve it.
-
7. Re: code to update mbean attribute value thru programatically.
ctomc Nov 27, 2014 8:09 AM (in response to rajajboss)maxpoolsize value or description as in metadata of attribute?
-
8. Re: code to update mbean attribute value thru programatically.
rajajboss Nov 27, 2014 8:15 AM (in response to ctomc)it is maxpoolsize description
-
9. Re: code to update mbean attribute value thru programatically.
rajajboss Nov 28, 2014 12:04 AM (in response to ctomc)Hi,
it is maxpoolsize's description not value.
Kindly help
-
10. Re: code to update mbean attribute value thru programatically.
rajajboss Dec 4, 2014 7:37 AM (in response to rajajboss)Hi ,
When I am updating mbean attribute value of type boolean, am getting the bellow error.please note that it is not java.lang.Boolean.But It is working for java.lang.Boolean type.
Code:
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.Boolean")||editedAttribute.getType().equals("boolean"));
//changedAttributeValue = new javax.management.Attribute(editedAttribute.getName(), new Boolean(editedAttribute.getValue()));
changedAttributeValue = new javax.management.Attribute(editedAttribute.getName(), Boolean.valueOf(editedAttribute.getValue()));
connection.setAttribute(objectName,changedAttributeValue);
System.out.println("attrinute value changed..........................");
} catch (Exception e) {
// TODO Auto-generated catch block
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