Java Reference
In-Depth Information
code to look for an instance of the
JMXBookAgent
class, or you can have it use the
MBean server in JBoss.
14.5.4
Generating EJB managers
When creating MBeans for managing
EJB
s, you usually expose the methods from
the
EJB
's remote interface. If this will typically be the case for your own
JMX
development, consider writing a utility class that can generate MBeans from an
EJB
remote interface. A utility class could generate Java source for MBeans, or it
could generate
ModelMBeanInfo
to place in Model MBeans of a
JMX
agent.
Listing 14.11 shows a class that generates MBean source files based on the
remote interface from an
EJB
. The generated MBeans are Dynamic MBeans that
extend the
DynamicMBeanSupport
class you developed in chapter 4. We won't spend
time discussing this class, but rather we will leave it as an exercise for you to do
with as you please.
Listing 14.11
EJBMBeanGenerator.java
package jmxbook.ch14;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
public class EJBMBeanGenerator
{
private String remoteInterface = null;
private String remoteInterfaceClass = null;
private Hashtable atts = null;
private Hashtable attTypes = null;
private Hashtable opsArgTypes = null;
private Hashtable opsReturns = null;
private Vector ops = null;
private Vector opNames = null;
private PrintWriter out = null;
public EJBMBeanGenerator( String remoteInterfaceClassName )
{
remoteInterfaceClass = remoteInterfaceClassName;
remoteInterface = remoteInterfaceClassName.substring(
remoteInterfaceClassName.lastIndexOf( "." ) + 1 );
}
public void buildMBean( String location )
{
try
{
Class remote = Class.forName( remoteInterfaceClass );
buildAttributesAndOperations( remote );
Init generator
with EJB
interface