Using MBeanRegistration
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
Listener
Tutorials
Cookbook

Find this tutorial in: /usr/local/resin/webapps/resin-doc/jmx/tutorial/registration
Try the Tutorial
MBeans can implement the MBeanRegistration interface to find the ObjectName and MBeanServer they're registered with.

  1. Files in this tutorial
  2. MBeanRegistration
    1. Client
  3. Compatibility

Files in this tutorial

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

MBeanRegistration

Frequently, a managed bean will either need its ObjectName or its MBeanServer. When the bean implements the MBeanRegistration interface, the JMX server tells the bean its ObjectName on registration.

The bean can verify the ObjectName or even returning a different name, although returning a different ObjectName is generally a bad idea in most cases since it makes the to configure.

Test.java
package example;

import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.management.MBeanRegistration;

public class Test implements TestMBean, MBeanRegistration {
  private ObjectName _name;

  public ObjectName getObjectName()
  {
    return _name;
  }
  
  public ObjectName preRegister(MBeanServer server, ObjectName name)
    throws Exception
  {
    _name = name;

    return name;
  }
  
  public void postRegister(Boolean registrationDone)
  {
  }
  
  public void preDeregister()
    throws Exception
  {
  }
  
  public void postDeregister()
  {
  }
}

Client

The client JSP asks for the object's ObjectName to see the ObjectName passed in the preRegistration call.

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

out.println("ObjectName: " + test.getObjectName());
%>

ObjectName: example:name=test

Compatibility

MBeanRegistration is part of the JMX specification.

Try the Tutorial


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