Results 1 to 6 of 6

Thread: Is here a category of JMX?

  1. #1

    Default Is here a category of JMX?

    Hello,

    Iīm looking for some Information about Spring with JMX but there isnīt a category for that.

    I tried the examples written by Rob Harrop but they doesnīt work. Maybe I made some mistakes but it is a very easy example.

    First thing is: he didnīt use the right package-name. "org.springframework.jmx.MBeanExporter" doesnīt exist in 1.2RC1. Itīs "org.springframework.jmx.export.MBeanExporter" .

    Thatīs not a big problem, I find the right one. I configured it like the example. But it seems that the container ignored the "MBeanExporter". There are no infos that he (the container) find or use it. I got only messages for the normal shared beans I want to expose to the mbean-server. I tried it with a running mbean-server I started before configuration of spring-container. And I tried it with the "MBeanServerFactoryBean" with a MX4J-Implementation in the classpath.

    So, if any read this stuff I wrote, maybe give me some feedback for this problem or post some other (maybe better) examples for using JMX with the springframework.

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    There is some draft documentation on the Wiki - but you are right tat some of the package names have changed during our refactoring efforts.

    Can you post your context configuration and the code you are using to load the context?

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3

    Default Configuration and Bean

    Hi Rob,

    nice to meet you.

    I tried both examples.
    Here is the configuration for my first try.
    Code:
    <?xml version="1.0" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="myFirstBean" class="net.jbellmann.spring.test.MyBean">
    		<property name="name">
    			<value>Bello</value>
    		</property>
    		<property name="i">
    			<value>31</value>
    		</property>
    	</bean>
    	
    	<bean id="jmxAdapter" class="org.springframework.jmx.export.MBeanExporter">
    		<property name="beans">
    			<map>
    				<entry key="bean&#58;name=testBean1">
    					<ref local="myFirstBean"/>
    				</entry>
    			</map>
    		</property>
    		<property name="server">
    			<ref local="mbeanServer" />
    		</property>
    	</bean>
    	
    	<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
    </beans>
    Here is the Bean for both examples.
    Code:
    package net.jbellmann.spring.test;
    
    /**
     * @author Bello
     *
     */
    public class MyBean implements IMyBean&#123;
    	
    	private static final String NAME = "Mein Name ist&#58; ";
    	private static final String ALTER = "Mein Alter ist&#58; ";
    	private static final String FREE = " ";
    	private static final String BREAK = "\n";
    	
    	private String name;
    	private int i;
    	
    	public MyBean&#40;&#41;&#123;
    		//
    	&#125;
    
    	public int getI&#40;&#41; &#123;
    		return i;
    	&#125;
    	
    
    	public void setI&#40;int i&#41; &#123;
    		this.i = i;
    	&#125;
    	
    
    	public String getName&#40;&#41; &#123;
    		return name;
    	&#125;
    	
    
    	public void setName&#40;String name&#41; &#123;
    		this.name = name;
    	&#125;
    	
    	public String toString&#40;&#41;&#123;
    		StringBuffer sb = new StringBuffer&#40;&#41;;
    		sb.append&#40;NAME&#41;;
    		sb.append&#40;name&#41;;
    		sb.append&#40;BREAK&#41;;
    		sb.append&#40;ALTER&#41;;
    		sb.append&#40;i&#41;;
    		sb.append&#40;FREE&#41;;
    		return sb.toString&#40;&#41;;
    	&#125;
    
    &#125;
    Itīs nearly the same as on your examples.
    Here I had the following jarīs in Classpath. mx4j; mx4j-tools and commons-logging.
    MX4J is the JMX-Implementation, i think you know it.

    Ok the output on console is:
    Code:
    13.04.2005 18&#58;03&#58;09 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO&#58; Loading XML bean definitions from file &#91;C&#58;\myProjects\SpringTest\conf\beans.xml&#93;
    13.04.2005 18&#58;03&#58;09 org.springframework.core.CollectionFactory <clinit>
    INFO&#58; JDK 1.4+ collections available
    13.04.2005 18&#58;03&#58;10 org.springframework.beans.factory.support.AbstractBeanFactory getBean
    INFO&#58; Creating shared instance of singleton bean 'myFirstBean'
    Mein Name ist&#58; Bello
    Mein Alter ist&#58; 31
    There are no information on any jmx-specifics.

    I tried it also with a started MBean-Server before instantiating/starting the spring-container. The configuration-file will follow. The result is the same.
    No information on any jmx-action in the spring-container.

    Code:
    Application configured successfully
    HttpAdaptor version 3.0.1 started on port 9090
    13.04.2005 18&#58;08&#58;39 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO&#58; Loading XML bean definitions from file &#91;C&#58;\myProjects\SpringTest\conf\beans.xml&#93;
    13.04.2005 18&#58;08&#58;39 org.springframework.core.CollectionFactory <clinit>
    INFO&#58; JDK 1.4+ collections available
    13.04.2005 18&#58;08&#58;39 org.springframework.beans.factory.support.AbstractBeanFactory getBean
    INFO&#58; Creating shared instance of singleton bean 'myFirstBean'
    Mein Name ist&#58; Bello
    Mein Alter ist&#58; 31
    conf:

    Code:
    <?xml version="1.0" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="myFirstBean" class="net.jbellmann.spring.test.MyBean">
    		<property name="name">
    			<value>Bello</value>
    		</property>
    		<property name="i">
    			<value>31</value>
    		</property>
    	</bean>
    	
    	<bean id="jmxAdapter" class="org.springframework.jmx.export.MBeanExporter">
    		<property name="beans">
    			<map>
    				<entry key="bean&#58;name=testBean1">
    					<ref local="myFirstBean"/>
    				</entry>
    			</map>
    		</property>
    	</bean>
    </beans>
    Ok, thatīs all I can post. If you need further information, no problem.
    If I understand you right, there is nothing more to do to get it running.

    Thank you

  4. #4
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    It looks like you may be using a BeanFactory to load the Spring configuration. If you do this the MBeanExporter won't be found automatically. Instead you should use an ApplicationContext implementation like ClassPathXmlApplicationContext.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  5. #5

    Default JMX and Spring works

    Hi Rob,

    thanks for your reply. It works now fine with MBeanServerFactoryBean and ClassPathXMLApplicationContext.

    With a running MBean-Server, started before Spring-Container, I got a MBeanServerNotFoundException. Donīt know why.

    So, I played a little bit with HttpAdaptor and XSLTProcessor from MX4J and got it running. I will contribute this here for some other which are interessted in.

    Itīs up to you to take it for new examples in the wiki-draft-documentation.
    But you donīt have to.

    If there is a way me to support this wiki or spring generally with some tuts or documents, write me a message.

    Here it is:

    Code:
    package net.jbellmann.spring.test;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.event.ContextRefreshedEvent;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class SpringFactoryUtil &#123;
    	
    	private static ApplicationContext context;
    	
    	static&#123;
    		context = new ClassPathXmlApplicationContext&#40;"beans.xml"&#41;;
    	&#125;
    	
    	public static Object getBean&#40;String name&#41;&#123;
    		return context.getBean&#40;name&#41;;
    	&#125;
    	
    	public static void refresh&#40;&#41;&#123;
    		context.publishEvent&#40;new ContextRefreshedEvent&#40;context&#41;&#41;;
    	&#125;
    
    &#125;
    Important here to use ClassPathXMLApplicationContext! thanks rob

    The MainClass:

    Code:
    package net.jbellmann.test;
    
    import java.io.IOException;
    
    import javax.management.MalformedObjectNameException;
    import javax.management.ObjectName;
    
    import mx4j.tools.adaptor.http.HttpAdaptor;
    import net.jbellmann.spring.test.MyBean;
    import net.jbellmann.spring.test.SpringFactoryUtil;
    
    /**
     * @author Bello
     *
     */
    public class MainClass &#123;
    	
    	/**
    	 * @param args
    	 */
    	public static void main&#40;String&#91;&#93; args&#41; &#123;
    		MainClass mc = new MainClass&#40;&#41;;
    		mc.startIt&#40;&#41;;
    	&#125;
    	
    	public void startIt&#40;&#41;&#123;
    		MyBean bean = &#40;MyBean&#41;SpringFactoryUtil.getBean&#40;"myFirstBean"&#41;;
    		System.out.println&#40;bean.toString&#40;&#41;&#41;;
    		HttpAdaptor httpAdaptor = &#40;HttpAdaptor&#41;SpringFactoryUtil.getBean&#40;"httpConnector"&#41;;
    		try &#123;
    			ObjectName on = ObjectName.getInstance&#40;"bean&#58;name=xsltProcessor"&#41;;
    			httpAdaptor.setProcessorName&#40;on&#41;;
    			httpAdaptor.start&#40;&#41;;
    		&#125; catch &#40;IOException e&#41; &#123;
    			e.printStackTrace&#40;&#41;;
    		&#125; catch &#40;MalformedObjectNameException e&#41; &#123;
    			e.printStackTrace&#40;&#41;;
    		&#125; catch &#40;NullPointerException e&#41; &#123;
    			e.printStackTrace&#40;&#41;;
    		&#125;
    	&#125;
    &#125;
    and the Configuration-File:

    Code:
    <?xml version="1.0" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="myFirstBean" class="net.jbellmann.spring.test.MyBean">
    		<property name="name">
    			<value>Bello</value>
    		</property>
    		<property name="i">
    			<value>31</value>
    		</property>
    	</bean>
    	
    	<bean id="jmxAdapter" class="org.springframework.jmx.export.MBeanExporter">
    		<property name="beans">
    			<map>
    				<entry key="bean&#58;name=testBean1">
    					<ref local="myFirstBean"/>
    				</entry>
    				<entry key="bean&#58;name=httpConnector">
    					<ref local="httpConnector"/>
    				</entry>
    				<entry key="bean&#58;name=xsltProcessor">
    					<ref local="xsltProcessor"/>
    				</entry>
    			</map>
    		</property>
    		<property name="server">
    			<ref local="mbeanServer" />
    		</property>
    	</bean>
    	
    	<bean id="httpConnector" class="mx4j.tools.adaptor.http.HttpAdaptor">
    		<property name="port">
    			<value>9090</value>
    		</property>
    		<property name="host">
    			<value>localhost</value>
    		</property>
    	</bean>
    
    	<bean id="xsltProcessor" class="mx4j.tools.adaptor.http.XSLTProcessor" />
    
    	<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
    </beans>
    For playing with the MBeans, open a browser with
    Hope, everybody is understanding my bad english writing. But if could here me, you would run away.

    Greetings from Berlin / Germany

    Thanks again to Rob for the fast reply.

  6. #6

    Default Delete the refresh-Method

    Hi,

    in the code i posted before is a method that should not be there. Delete the
    refresh() - Mehtod in SpringFactoryUtil
    I donīt use this method in the example posted. It was only a little test.

    Bello

Similar Threads

  1. Spring -hibernate Integration (CGLIB error)
    By avinashb in forum Architecture
    Replies: 1
    Last Post: Oct 13th, 2005, 07:08 AM
  2. authorisation more complex than isUserInRole
    By derKaiser in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 10:51 AM
  3. Submitting Form gives ClassCastException
    By curtney in forum Web Flow
    Replies: 9
    Last Post: Jul 7th, 2005, 08:32 PM
  4. Replies: 0
    Last Post: Jan 30th, 2005, 11:14 AM
  5. Circular Dependency Nightmare
    By pburleson in forum Container
    Replies: 2
    Last Post: Nov 11th, 2004, 01:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •