Simple JMX-managed Resource
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Servlet
JMX Consoles
Instrumenting
Tutorials
Cookbook

Basic JMX
MBeanServer
Listener
Registration
Tutorials
Tutorials
MBeanServer

Find this tutorial in: /usr/local/resin/webapps/resin-doc/jmx/tutorial/basic
Try the Tutorial
Resources can be JMX managed by exposing a management interface and registering as an MBean.

  1. Files in this tutorial
  2. JMX Resource
    1. MBean names
    2. web.xml configuration
    3. Using the resource proxy
  3. Compatibility

Files in this tutorial

WEB-INF/web.xml Configures the JMX-managed bean
WEB-INF/classes/example/Basic.java The resource bean implementation.
WEB-INF/classes/example/BasicMBean.java The management interface for the bean.
index.jsp Using the managed bean.

JMX Resource

Any 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 Basic bean is the example resource implementation. It exposes its managed interface by implementing a BasicMBean interface. The xxxMBean naming convention lets JMX determine which interface to use for management. The MBean interface will expose the Data attribute to JMX.

Basic.java
package example;

public class Basic implements BasicMBean {
  private String _data = "default";

  public void setData(String data)
  {
    _data = data;
  }

  public String getData()
  {
    return _data;
  }
}

BasicMBean is the bean's management interface. It exposes a single attribute, Data, as a getter/setter pair. The name of the interface is important. Since the resource is named Basic, the MBean interface will be named BasicMBean.

BasicMBean.java
package example;

public interface BasicMBean {
  public void setData(String data);

  public String getData();
}

MBean names

MBeans are stored in the MBean server using an ObjectName as its key. Essentially, the MBean server stores the managed beans in a map using the mbean name as a key.

The mbean name consists of a set of <name,value> properties and a "domain" used like a namespace. The properties allow for querying related mbeans. For example, you could request for all mbeans with "J2EEType=Servlet", which would return all the managed servlets.

The example uses the name "example:name=basic". "example" is the domain and the bean's single property is "name" with a value of "basic". By convention, an mbean would normally also have a "type" property, but this example is using a name as simple as possible.

web.xml configuration

The 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 mbean-name.

web.xml
<web-app xmlns="http://caucho.com/ns/resin">
  <resource mbean-name="example:name=basic" type="example.Basic">
    <init>
      <data>An Example Resource</data>
    </init>
  </resource>
</web-app>

tagdescription
resourcedefines the resource
mbean-namethe MBean name of the resource
typethe class name of the resource bean
initAny bean-style configuration goes here
dataThe example bean's setData parameter.

Using the resource proxy

Resin's JMX implementation provides a proxy to managed object using the interface for an API. You can, of course, use the standard JMX interface, the proxy interface is much easier to use.

index.jsp
<%@ page import='com.caucho.jmx.Jmx, example.BasicMBean' %>
<%
BasicMBean basic = (BasicMBean) Jmx.find("example:name=basic");

out.println("data: " + basic.getData());
%>

data: An example resource

Compatibility

The resource's code is completely compatible with other JMX implementations. The proxy interface, however, is unique to Resin. If you choose, you can use the JMX API to access the resource. The configuration, of course, is Resin-dependent.

Try the Tutorial


Tutorials
Tutorials
MBeanServer
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.