View Full Version : Creating a proxy to a java.lang.management.MemoryMXBean
eddstar
Sep 11th, 2007, 01:54 AM
Hello all,
I attempting to create a proxy to a MemoryMXBean. The interface is: java.lang.management.MemoryMXBean and the object name is: java.lang:type=Memory. This is per the javadocs: http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/lang/management/MemoryMXBean.html
My spring config is as follows:
<beans>
<bean id="memProxy" class="org.springframework.jmx.access.MBeanProxyFactoryBe an">
<property name="objectName" value="java.lang:type=Memory"/>
<property name="proxyInterface" value="java.lang.management.MemoryMXBean"/>
</bean>
</beans>
The java code that is attempting to use the proxy is the following:
ApplicationContext context = new ClassPathXmlApplicationContext("..\\jmxTest.xml");
MemoryMXBean memoryMXBean = (MemoryMXBean) context.getBean("memProxy");
memoryMXBean.gc();
long heapMemoryUsed = memoryMXBean.getHeapMemoryUsage().getUsed();
The application context is being created, the MemoryMXBean is being set, and the gc method of memoryMXBean is being called correctly, however, after the call to memoryMXBean.getHeapMemoryUsage().getUsed(); is being performed the following exception.getMessage is being shown: "javax.management.openmbean.CompositeDataSupport" and the following exception.getStackTrace is being shown: "[Ljava.lang.StackTraceElement;@787c16"
Any ideas as to why this might be? Any comments would be greatly appreciated.
Thanks.
SLivengood
Sep 11th, 2007, 04:53 PM
I am also seeing issues accessing composite properties of MemoryMXBean via Spring's JMX proxy.
From the injected proxy MemoryMXBean memBean, I can successfully access memBean.getObjectPendingFinalizationCount(), but if I try to access memBean.getHeapMemoryUsage().getCommitted() I get the stacktrace seen below.
I can verify the MBean exists by using JConsole and if I use memBean=ManagementFactory.getMemoryMXBean() everything works fine.
Are there limitations around using Spring to create a proxy and accessing Composite data, or is there something else I am missing or doing incorrectly?
Stacktrace
java.lang.ClassCastException: javax.management.openmbean.CompositeDataSupport
at $Proxy1.getHeapMemoryUsage(Unknown Source)
at com.foo.web.controller.JmxController.handleRequest Internal(JmxController.java:21)
...
Beans
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactory Bean">
<property name="locateExistingServerIfPossible" value="true"></property>
</bean>
<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBe an">
<property name="objectName" value="java.lang:type=Memory"/>
<property name="proxyInterface" value="java.lang.management.MemoryMXBean"/>
</bean>
<bean name="jmx" class="com.foo.web.controller.JmxController" >
<property name="memBean" ref="proxy"></property>
</bean>
Controller
public class JmxController extends ParameterizableViewController{
private java.lang.management.MemoryMXBean memBean;
public void setMemBean(java.lang.management.MemoryMXBean memBean) {
this.memBean = memBean;
}
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
MemoryUsage memUsage = memBean.getNonHeapMemoryUsage();
return new ModelAndView(getViewName(),"test",Long.toString(memUsage.getCommitted()));
}
}
Additional Info:
Tomcat version: 5.5.23
Java version: 1.5.0_06-112
Spring version: 2.0.5
Juergen Hoeller
Sep 28th, 2007, 05:02 PM
MXBean data structures are not explicitly supported in Spring 2.0.x; however, we've just added support for automatic conversion of CompositeData/TabularData structures for Spring 2.5! This should already be available in the next 2.5 RC1 snapshot.
Juergen
shashi
Apr 21st, 2010, 06:24 AM
Hi,
I too am facing this problem. As per the last comment for this thread this should have been fixed in 2.5, am using 3.0.1.RELEASE-A spring version, however still getting the same problem.
java.lang.ClassCastException: javax.management.openmbean.CompositeDataSupport
at $Proxy171.getHeapMemoryUsage(Unknown Source)
at com.arisglobal.aglite.osgi.CommandHelper.getMonito ringStatistics(CommandHelper.java:192)
at com.arisglobal.aglite.osgi.CommandHelper._agLite(C ommandHelper.java:82)
at com.arisglobal.aglite.osgi.CommandHelper._aglite(C ommandHelper.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.osgi.framework.internal.core.Framework CommandInterpreter.execute(FrameworkCommandInterpr eter.java:155)
at org.eclipse.osgi.framework.internal.core.Framework Console.docommand(FrameworkConsole.java:303)
at org.eclipse.osgi.framework.internal.core.Framework Console.console(FrameworkConsole.java:288)
at org.eclipse.osgi.framework.internal.core.Framework Console.run(FrameworkConsole.java:224)
at java.lang.Thread.run(Thread.java:595)
I have need to use mbeans in clustered manner, hence I obtain the beans using JMXConnectorFactory and invoke the operations on proxy obtained using MBeanServerInvocationHandler.newProxyInstance api.
Let me know if there is any solution for this.
Regards,
Shashi
shashi
Apr 22nd, 2010, 12:05 AM
Hi,
When I used springs MBeanProxyFactoryBean to get the proxy for the memory mbeans it started working.
However as I mentioned in my previous post, I need to access the remote mbeans which are clustered, and the remote address would be constructed at runtime. In that case I would have to dynamically create MBeanProxyFactoryBean instances and register in the spring context. That is feasible but in that case I would have to write a custom bean post processor which does the registration job.
Please let me know if this is the best way to do it.
Regards,
Shashi
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.