PDA

View Full Version : JMX Server/Client implementation problems



victor
Dec 5th, 2006, 10:33 AM
Hello,
I'm trying to implement JMX server side and client side.

I have the following xml in the server side:


<beans>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactor yBean">
<property name="port" value="8335" />
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFac toryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost:8100/jndi/rmi://localhost:8335/server" />
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactory Bean" />
<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=testBean1" value-ref="testBean" />
</map>
</property>
<property name="server" ref="mbeanServer" />
</bean>
<bean id="testBean" class="com.jacada.jmx.JacadaJmxImpl">
</bean>
</beans>

And here's my client side:


<beans>
<bean id="clientConnector"
class="org.springframework.jmx.support.MBeanServerConnect ionFactoryBean">
<property name="serviceUrl"
value="service:jmx:rmi:///jndi/rmi://localhost:8335/server" />
</bean>
<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBe an">
<property name="objectName" value="bean:name=testBean1" />
<property name="proxyInterface"
value="com.jacada.jmx.JacadaJmx" />
<property name="server" ref="clientConnector" />
</bean>
</beans>

The server side looks OK
But there's an exception on the client side:


Dec 5, 2006 6:22:17 PM org.springframework.core.CollectionFactory <clinit>
INFO: JDK 1.4+ collections available
Dec 5, 2006 6:22:17 PM org.springframework.core.CollectionFactory <clinit>
INFO: Commons Collections 3.x available
Dec 5, 2006 6:22:17 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext-client.xml]
Dec 5, 2006 6:22:17 PM org.springframework.context.support.AbstractRefres hableApplicationContext refreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext;hashCode=5947506]: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [clientConnector,proxy]; root of BeanFactory hierarchy
Dec 5, 2006 6:22:17 PM org.springframework.context.support.AbstractApplic ationContext refresh
INFO: 2 beans defined in application context [org.springframework.context.support.ClassPathXmlAp plicationContext;hashCode=5947506]
Dec 5, 2006 6:22:17 PM org.springframework.context.support.AbstractApplic ationContext initMessageSource
INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMess ageSource@1e0be38]
Dec 5, 2006 6:22:17 PM org.springframework.context.support.AbstractApplic ationContext initApplicationEventMulticaster
INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicatio nEventMulticaster@7a84e4]
Dec 5, 2006 6:22:17 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [clientConnector,proxy]; root of BeanFactory hierarchy]
Dec 5, 2006 6:22:17 PM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
INFO: Destroying singletons in {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [clientConnector,proxy]; root of BeanFactory hierarchy}
Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'proxy' defined in class path resource [applicationContext-client.xml]: Invocation of init method failed; nested exception is org.springframework.jmx.access.MBeanInfoRetrievalE xception: Unable to obtain MBean info for bean [bean:name=testBean1]: it is likely that this bean was unregistered during the proxy creation process; nested exception is javax.management.InstanceNotFoundException: bean:name=testBean1
Caused by: org.springframework.jmx.access.MBeanInfoRetrievalE xception: Unable to obtain MBean info for bean [bean:name=testBean1]: it is likely that this bean was unregistered during the proxy creation process; nested exception is javax.management.InstanceNotFoundException: bean:name=testBean1
Caused by: javax.management.InstanceNotFoundException: bean:name=testBean1
at com.sun.jmx.interceptor.DefaultMBeanServerIntercep tor.getMBean(DefaultMBeanServerInterceptor.java:10 10)
at com.sun.jmx.interceptor.DefaultMBeanServerIntercep tor.getMBeanInfo(DefaultMBeanServerInterceptor.jav a:1303)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getMBeanInf o(JmxMBeanServer.java:903)
at javax.management.remote.rmi.RMIConnectionImpl.doOp eration(RMIConnectionImpl.java:1402)
at javax.management.remote.rmi.RMIConnectionImpl.acce ss$100(RMIConnectionImpl.java:81)
at javax.management.remote.rmi.RMIConnectionImpl$Priv ilegedOperation.run(RMIConnectionImpl.java:1245)
at javax.management.remote.rmi.RMIConnectionImpl.doPr ivilegedOperation(RMIConnectionImpl.java:1341)
at javax.management.remote.rmi.RMIConnectionImpl.getM BeanInfo(RMIConnectionImpl.java:858)
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 sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:1 53)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(Str eamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:1 26)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub .getMBeanInfo(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBe anServerConnection.getMBeanInfo(RMIConnector.java: 1031)
at org.springframework.jmx.access.MBeanClientIntercep tor.retrieveMBeanInfo(MBeanClientInterceptor.java: 226)
at org.springframework.jmx.access.MBeanClientIntercep tor.afterPropertiesSet(MBeanClientInterceptor.java :190)
at org.springframework.jmx.access.MBeanProxyFactoryBe an.afterPropertiesSet(MBeanProxyFactoryBean.java:7 2)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1057)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1024)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:421)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 45)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:140)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:270)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:346)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:92)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:77)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:68)
at com.jacada.jmx.MainClient.main(MainClient.java:9)



What is wrong?
Thank you in advance.
Victor.

Costin Leau
Dec 5th, 2006, 11:31 AM
I haven't worked with JMX and RMI in a long time but it seems that your server publishes the bean under:
service:jmx:rmi://localhost:8100/jndi/rmi://localhost:8335/server
while your client looks for the bean under:
service:jmx:rmi:///jndi/rmi://localhost:8335/server

victor
Dec 5th, 2006, 11:15 PM
Than you.

I've tried to change the url in the client so it will be the same as in the server, but I've got the same exception.

Victor.

Costin Leau
Dec 6th, 2006, 07:05 AM
You could use jconsole to connect to the server using the client connector and browse the existing MBeans. You might be running into a lazy loading issue - you bean is not exposed since it wasn't used yet and thus it hasn't been instantiated yet.

victor
Dec 6th, 2006, 07:21 AM
I've added lazy-init="false" to my beans - same result.
I've connected with jconsole and I can not see the MBean (I see only the connector/rmi MBean which is the serverConnector).

my new server applicationContext.xml:



<beans>
<bean id="registry"
class="org.springframework.remoting.rmi.RmiRegistryFactor yBean">
<property name="port" value="8335" />
</bean>

<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFac toryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost:8100/jndi/rmi://localhost:8335/server" />
</bean>

<bean id="mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactory Bean" lazy-init="false"/>

<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">

<property name="beans">
<map>
<entry key="connector:name=testBean1" value-ref="testBean" />
</map>
</property>
<property name="server" ref="mbeanServer" />
</bean>

<bean id="testBean" class="com.jacada.jmx.JacadaJmxImpl" lazy-init="false">
</bean>
</beans>

Dave Syer
Dec 7th, 2006, 02:27 AM
Have you checked your firewall settings on the client and server? In the extreme case it could be that the registry is not even being created (did you say you could see the connector in jconsole?). If you can, just disable firewalls on both machines until you can work out what is happening.

victor
Dec 7th, 2006, 03:58 AM
Thank you David,

both client and server are running on the same machine, and both of them are configured with "localhost" as hostname.
So it probably something else.

Victor.

Dave Syer
Dec 7th, 2006, 07:09 AM
As far as I know "localhost" is not immune from firewalls. I have a firewall on my PC, and it has to be explicitly either disabled or tweaked to allow me to create an rmi registry. Just check if you have any firewall running and disable it if you find one while you test your server-client.

victor
Dec 13th, 2006, 04:23 AM
Hello all,

I know what was the problem and I think that I have a solution.

The problem was that in the runtime there were 2 MBeanServers, and the client query was ponting to the wrong one.

To solve it I've removed "mbeanServer" bean from the server context.
The server context xml:


<beans>
<bean id="registry"
class="org.springframework.remoting.rmi.RmiRegistryFactor yBean">
<property name="port" value="8335" />
</bean>

<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFac toryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost:8100/jndi/rmi://localhost:8335/server" />
</bean>

<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">

<property name="beans">
<map>
<entry key="connector:name=testBean1" value-ref="testBean" />
</map>
</property>
</bean>

<bean id="testBean" class="com.jacada.jmx.JacadaJmxImpl" lazy-init="false">
</bean>
</beans>


Victor.

Juergen Mayrbaeurl
Jan 9th, 2007, 10:10 AM
I think removing the MBeanServer creation won't work, if the app is run with JRE 1.4.2 and/or JRE 5.

We're using the following setup:


<bean id="mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactory Bean"
depends-on="jmx_registry">

<property name="locateExistingServerIfPossible" value="true"/>
<property name="defaultDomain" value="${verst.jmx.domain}"/>

</bean>


Kind regards
Juergen