| ||||||||||||||||||||||||||||||||
Resin 3.1 Documentation Examples Changes Quercus Database Amber EJB SOA/ESB IoC JMS Servlet JMX Hessian Security Basic Listener Registration MBeanServer |
Example showing JMX-managed resources using the MBeanServer API. Files in this tutorial
JMX ResourceAny resource in Resin can be managed by JMX by implementing an MBean interface and by specifying an MBean name. The interface exposes the resource's methods to be managed. The Test resourceThe test resource is identical to the
basic example but implements
package example; public class Test implements TestMBean { private String _data = "default"; public void setData(String data) { _data = data; } public String getData() { return _data; } } web.xml configurationThe web.xml (or resin.conf) configures the resource with the <resource> tag just as with other resources. The resources is registered as an MBean by specifying an . <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>
Using MBeanServerMBeanServer is the main JMX interface for managing resources. Although it is less convenient than Resin's proxy interface, it has the advantage of being part of the JMX standard. Resin stores the MBeanServer it uses for resources in JNDI under the name java:comp/env/jmx/MBeanServer. Applications will use JNDI to get the MBeanServer. This JNDI name is not specified in any standard, so applications might want to encapsulate getting the MBeanServer in a class that can be changed easily. All management of an MBean uses the MBeanServer and the MBean's ObjectName. In this case, the ObjectName is "example:name=test". The MBeanServer has three primary management calls:
<%@ page import='javax.naming.*, javax.management.*, example.TestAdmin' %> <% Context ic = new InitialContext(); MBeanServer server = (MBeanServer) ic.lookup("java:comp/env/jmx/MBeanServer"); ObjectName name = new ObjectName("example:name=test"); out.println("data: " + server.getAttribute(name, "Data")); %> data: An example resource CompatibilityUsing the MBeanServer interface is compatible with other JMX implementations. The two Resin-dependencies are the configuration and how to obtain the Resin MBeanServer. Different JMX implementations will use a different technique to get the MBeanServer, so it's a good idea to encapsulate getting the MBeanServer in a class that you can change for different implementations.
|