Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Spring Management

Reply
 
Thread Tools Display Modes
  #1  
Old Mar 28th, 2008, 05:40 AM
zebthecat zebthecat is offline
Member
 
Join Date: Nov 2006
Posts: 86
Default 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
Reply With Quote
  #2  
Old Mar 28th, 2008, 06:08 AM
Marten Deinum Marten Deinum is offline
Senior Member
 
Join Date: Jun 2006
Location: The Netherlands
Posts: 9,296
Default

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.
__________________
Marten Deinum
  • Senior Java Consultant
  • SpringSource Certified Trainer
Conspect ICT diensten
Blog
LinkedIn
Use the [ code ] tags, young padawan
Reply With Quote
  #3  
Old Mar 28th, 2008, 07:52 AM
zebthecat zebthecat is offline
Member
 
Join Date: Nov 2006
Posts: 86
Default 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
Reply With Quote
  #4  
Old Apr 7th, 2008, 04:32 AM
zebthecat zebthecat is offline
Member
 
Join Date: Nov 2006
Posts: 86
Thumbs up 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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:07 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.