Java Reference
In-Depth Information
■
RuntimeOperationsException
—This exception wraps an
IllegalArgument-
Exception
indicating that the object name is invalid or
null
.
8.2.2
Creation and registration methods
The
registerMBean()
method shown in the previous section registers an MBean
that is already created. The MBean server also has four methods that let you cre-
ate and register an MBean with one method call. Table 8.2 shows two of these
methods that we will discuss in the following sections.
Table 8.2
MBean creation-related methods of the
MBeanServer
interface
Method
Purpose
Creates and registers a new MBean of the given class
createMBean( String className,
ObjectName name )
Creates and registers a new MBean of the given class using
the class loader referenced by the given
ObjectName
loader
createMBean( String className,
ObjectName name, ObjectName
loader )
The remaining two methods are overloaded, adding additional parameters; you
can look them up in the
JMX
javadoc available with the
RI
. Using the
create-
MBean()
methods tells the MBean server to instantiate a particular instance of an
MBean class as well as register the new instance. This process allows clients of a
JMX
agent such as management applications or other programs to delegate the
creation of MBeans to the agent. Outside processes need only supply the correct
information and parameters, and the agent's MBean server will do the rest.
The createMBean( String className, ObjectName name ) method
The first
createMBean()
method accepts the MBean's classname as a
String
and an
ObjectName
instance for registering the new MBean. This method uses
Java reflection to instantiate an instance of the supplied classname. The class
must contain a default constructor (a no-argument public constructor). In
addition, the resulting MBean instance must conform to the MBean validation
rules described in chapters 3, 4, 6, and 7. Also, the supplied
ObjectName
must
be valid and unique. The various
createMBean()
methods can throw many
exceptions, including:
■
ReflectionException
—The exception wraps a
ClassNotFoundException
or
any exception that occurs while trying to invoke the class's constructor to
instantiate the MBean.