Caucho Technology

using mbeanregistration


MBeans can implement the MBeanRegistration interface to find the ObjectName and MBeanServer they're registered with.

Demo

Files in this tutorial

FILEDESCRIPTION
WEB-INF/web.xmlConfigures the JMX-managed bean
WEB-INF/classes/example/Test.javaThe resource bean implementation.
WEB-INF/classes/example/TestMBean.javaThe management interface for the bean.
index.jspUsing the managed bean.

MBeanRegistration

Frequently, a managed bean will either need itsObjectNameor itsMBeanServer. When the bean implements theMBeanRegistrationinterface, the JMX server tells the bean itsObjectNameon registration.

The bean can verify theObjectNameor even returning a different name, although returning a differentObjectNameis 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 thepreRegistrationcall.

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.

Demo


Copyright © 1998-2011 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.