📄 index.xtp
字号:
<document> <header> <product>resin</product> <title>Using the JMX MBeanServer API</title> <type>tutorial</type> <description> <p> Example showing JMX-managed resources using the MBeanServer API. </p> </description> <tutorial-startpage>index.jsp</tutorial-startpage> </header><body><summary/><s1 title="Files in this tutorial"><deftable><tr><td><viewfile-link file="WEB-INF/web.xml"/> </td><td>Configures the JMX-managed bean</td></tr><tr><td><viewfile-link file="WEB-INF/classes/example/Test.java"/> </td><td>The resource bean implementation.</td></tr><tr><td><viewfile-link file="WEB-INF/classes/example/TestAdmin.java"/> </td><td>The management interface for the bean.</td></tr><tr><td><viewfile-link file="index.jsp"/> </td><td>Using the managed bean.</td></tr></deftable></s1><s1 title="JMX Resource"><p>Any resource in Resin can be managed by JMX by implementingan MBean interface and by specifying an MBean name. The interfaceexposes the resource's methods to be managed.</p><s2 title="The Test resource"><p>The test resource is identical to the<a href="../jmx-basic/index.xtp">basic example</a> but implements<code>TestAdmin</code> instead of <code>TestMBean</code>. Becausethe name <code>TestAdmin</code> does not conform to the MBean convention,the web.xml will need to specify the interface explicitly.</p><example title="Test.java">package example;public class Test implements TestMBean { private String _data = "default"; public void setData(String data) { _data = data; } public String getData() { return _data; }}</example></s2><s2 title="web.xml configuration"><p>The web.xml (or resin.conf) configures the resource with the<resource> tag just as with<a href="doc|ioc-bean.xtp">other resources</a>. The resources isregistered as an MBean by specifying an <var>mbean-name</var>.</p><example title="web.xml"><web-app xmlns="http://caucho.com/ns/resin"> <resource mbean-name="example:name=basic" type="example.Test" mbean-interface="example.TestAdmin> <init> <data>An Example Resource</data> </init> </resource></web-app></example><deftable><tr><th>tag</th><th>description</th></tr><tr><td>resource</td><td>defines the resource</td></tr><tr><td>mbean-name</td><td>the MBean name of the resource</td></tr><tr><td>type</td><td>the class name of the resource bean</td></tr><tr><td>mbean-interface</td><td>the class name to use as the managed interface</td></tr><tr><td>init</td><td>Any bean-style configuration goes here</td></tr><tr><td>data</td><td>The example bean's <code>setData</code> parameter.</td></tr></deftable></s2><s2 title="Using MBeanServer"><p>MBeanServer is the main JMX interface for managing resources.Although it is less convenient than Resin's proxy interface, it has theadvantage of being part of the JMX standard.</p><p>Resin stores the MBeanServer it uses for resources in WebBeans.Since MBeanServer is unique, the application can use <code>@In</code>to inject the server.</p><p>All management of an MBean uses the MBeanServer and the MBean'sObjectName. In this case, the ObjectName is "example:name=test".</p><p>The MBeanServer has three primary management calls:<code>getAttribute</code>, <code>setAttribute</code>,and <code>invoke</code>. This example just uses <code>getAttribute</code>.</p><example title="index.jsp"><%@ page import='javax.webbeans.In, javax.management.*, example.TestAdmin' %><%!@In MBeanServer _server;%><%ObjectName name = new ObjectName("example:name=test");out.println("data: " + _server.getAttribute(name, "Data"));%></example><results>data: An example resource</results></s2></s1><s1 title="Compatibility"><p>Using the MBeanServer interface is compatible with otherJMX implementations. The two Resin-dependencies are the configurationand how to obtain the Resin MBeanServer. Different JMX implementationswill use a different technique to get the MBeanServer, so it's a goodidea to encapsulate getting the MBeanServer in a class that you canchange for different implementations.</p></s1> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -