Accessing MBeans via Proxies

4.3.9.RELEASE Spring Framework 727 bean id = serverConnector class = org.springframework.jmx.support.ConnectorServerFactoryBean property name = objectName value = connector:name=iiop property name = serviceUrl value = service:jmx:iiop:localhostjndiiiop:localhost:900myconnector property name = threaded value = true property name = daemon value = true property name = environment map entry key = someKey value = someValue map property bean Note that when using a RMI-based connector you need the lookup service tnameserv or rmiregistry to be started in order for the name registration to complete. If you are using Spring to export remote services for you via RMI, then Spring will already have constructed an RMI registry. If not, you can easily start a registry using the following snippet of configuration: bean id = registry class = org.springframework.remoting.rmi.RmiRegistryFactoryBean property name = port value = 1099 bean Client-side Connectors To create an MBeanServerConnection to a remote JSR-160 enabled MBeanServer use the MBeanServerConnectionFactoryBean as shown below: bean id = clientConnector class = org.springframework.jmx.support.MBeanServerConnectionFactoryBean property name = serviceUrl value = service:jmx:rmi:localhostjndirmi:localhost:1099jmxrmi bean JMX over BurlapHessianSOAP JSR-160 permits extensions to the way in which communication is done between the client and the server. The examples above are using the mandatory RMI-based implementation required by the JSR-160 specification IIOP and JRMP and the optional JMXMP. By using other providers or JMX implementations such as MX4J you can take advantage of protocols like SOAP, Hessian, Burlap over simple HTTP or SSL and others: bean id = serverConnector class = org.springframework.jmx.support.ConnectorServerFactoryBean property name = objectName value = connector:name=burlap property name = serviceUrl value = service:jmx:burlap:localhost:9874 bean In the case of the above example, MX4J 3.0.0 was used; see the official MX4J documentation for more information.

31.6 Accessing MBeans via Proxies

Spring JMX allows you to create proxies that re-route calls to MBeans registered in a local or remote MBeanServer . These proxies provide you with a standard Java interface through which you can interact with your MBeans. The code below shows how to configure a proxy for an MBean running in a local MBeanServer : bean id = proxy class = org.springframework.jmx.access.MBeanProxyFactoryBean property name = objectName value = bean:name=testBean property name = proxyInterface value = org.springframework.jmx.IJmxTestBean bean 4.3.9.RELEASE Spring Framework 728 Here you can see that a proxy is created for the MBean registered under the ObjectName : bean:name=testBean . The set of interfaces that the proxy will implement is controlled by the proxyInterfaces property and the rules for mapping methods and properties on these interfaces to operations and attributes on the MBean are the same rules used by the InterfaceBasedMBeanInfoAssembler . The MBeanProxyFactoryBean can create a proxy to any MBean that is accessible via an MBeanServerConnection . By default, the local MBeanServer is located and used, but you can override this and provide an MBeanServerConnection pointing to a remote MBeanServer to cater for proxies pointing to remote MBeans: bean id = clientConnector class = org.springframework.jmx.support.MBeanServerConnectionFactoryBean property name = serviceUrl value = service:jmx:rmi:remotehost:9875 bean bean id = proxy class = org.springframework.jmx.access.MBeanProxyFactoryBean property name = objectName value = bean:name=testBean property name = proxyInterface value = org.springframework.jmx.IJmxTestBean property name = server ref = clientConnector bean Here you can see that we create an MBeanServerConnection pointing to a remote machine using the MBeanServerConnectionFactoryBean . This MBeanServerConnection is then passed to the MBeanProxyFactoryBean via the server property. The proxy that is created will forward all invocations to the MBeanServer via this MBeanServerConnection .

31.7 Notifications