Announcement Announcement Module
Collapse
No announcement yet.
Creating a proxy to a java.lang.management.MemoryMXBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating a proxy to a java.lang.management.MemoryMXBean

    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/...oryMXBean.html

    My spring config is as follows:
    <beans>
    <bean id="memProxy" class="org.springframework.jmx.access.MBeanProxyFa ctoryBean">
    <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.CompositeDataSuppo rt" 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.

  • #2
    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
    Code:
    java.lang.ClassCastException: javax.management.openmbean.CompositeDataSupport
    	at $Proxy1.getHeapMemoryUsage(Unknown Source)
    	at com.foo.web.controller.JmxController.handleRequestInternal(JmxController.java:21)
    ...
    Beans
    PHP Code:
    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
       <
    property name="locateExistingServerIfPossible" value="true"></property>
    </
    bean>

    <
    bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
       <
    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
    Code:
    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

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Code:
        java.lang.ClassCastException: javax.management.openmbean.CompositeDataSupport
        	at $Proxy171.getHeapMemoryUsage(Unknown Source)
        	at com.arisglobal.aglite.osgi.CommandHelper.getMonitoringStatistics(CommandHelper.java:192)
        	at com.arisglobal.aglite.osgi.CommandHelper._agLite(CommandHelper.java:82)
        	at com.arisglobal.aglite.osgi.CommandHelper._aglite(CommandHelper.java:98)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:585)
        	at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:155)
        	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:303)
        	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:288)
        	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.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

        Comment


        • #5
          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

          Comment

          Working...
          X