Announcement Announcement Module
Collapse
No announcement yet.
Dumb tomcat JMX client question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dumb tomcat JMX client question

    Hope someone can help.

    What I'd like to do is list tomcat sessions and destroy them, if required, in my Spring web-app and am stuck.

    I've switched JMX remoteing (not that I think I need it) on using JVM params and have found the tomcat management bean that does what I require in JConsole.

    My question is:
    How do I configure and use this MBean in Spring?

    I tried this:
    Code:
    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
       		<property name="locateExistingServerIfPossible" value="true"></property>
    	</bean> 
    
    	<bean id="sessionProxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
       		<property name="objectName" value="Catalina:type=Manager,path=/ep4,host=localhost"/>
       		<property name="proxyInterface" value="javax.management.modelmbean.ModelMBean"/>
    		<property name="server" ref="mbeanServer"/>
    	</bean>
    and injected the sessionProxy into a controller but I keep getting this Error or something similar:
    Code:
    org.springframework.jmx.access.InvalidInvocationException: Attribute 'MBeanInfo' is not exposed on the management interface
    I know I've got the bean name correct but have probably missed something obvious.

    If the answer is RTFM; which M do I Fing R.

    Thanks

  • #2
    Find out which interfaces the specific bean implements. Spring tries to call the getMBeanInfo method (that is specified on the interface) but apparently that isn't implemented by the underlying class.

    Comment


    • #3
      I thought I had...

      ...as JConsole told me the MBean's class was an org.apache.commons.modeler.BaseModelMBean which implements
      javax.management.modelmbean.ModelMBean (amongst others)

      which includes the getMBeanInfo() method.

      DEBUG logging org.springframework.jmx doesn't give me any clues either.

      I have definitely missed something - Thanks anyway

      Comment


      • #4
        Sorted

        Was barking up the wrong tree on this one. Was an easy fix in the end.

        Added a jmxServices bean:

        Code:
        <bean id="jmxServices" class="com.globalfilings.services.JMXServices">
        		<property name="managerName" value="Catalina:type=Manager,path=/ep4,host=localhost"/>
        		<property name="server" ref="mbeanServer"/>
        	</bean>
        and called this bit of code:

        Code:
        public List getSessionIds() {
        		List sessionList = null;
        		try {
        			ObjectName contextObjectName = new ObjectName(getManagerName());
        			String olist = (String)server.invoke(contextObjectName, "listSessionIds", null, null);
        		   	sessionList = new ArrayList(Arrays.asList(olist.split(" ")));
        		} catch (Exception e) {
        			log.error(e);
        		}
        		return sessionList;
        	}
        to get at the sessions and this:

        Code:
        public void expireSession(String sessionId){
        		ObjectName contextObjectName;
        		try {
        			contextObjectName = new ObjectName(getManagerName());
        			server.invoke(contextObjectName, "expireSession", new String[]{sessionId}, new String[]{"java.lang.String"});
        		} catch (Exception e) {
        			log.error(e);		
        		} 
        	}
        to destroy an existing session; easy peasy.

        Comment

        Working...
        X