Java Reference
In-Depth Information
C
The
getMBeanInfo()
method, declared by the
DynamicMBean
interface, defines the
management interface for this MBean. Your
WorkflowManager
MBean creates its
MBeanInfo
object around the methods in the
Workflow
EJB
's remote interface.
This
MBeanInfo
object exposes one operation,
advanceState()
, and one read/write
attribute,
State
. (We describe the
MBeanInfo
object and how to use the metadata
classes in chapter 4.)
The MBean's constructor called the
lookUpHome()
method in order to get a refer-
ence to the
EJB
's home interface. Because the MBean was provided with a
JNDI
name for the home interface, it simply makes a call to the
JNDI
lookup mecha-
nism to find the home object reference.
This MBean implements the methods declared by the
DynamicMBean
interface
specifically for its
EJB
. For example, the
getAttribute()
method compares the
incoming attribute name to see if it is
State
(the
setAttribute()
method does the
same). The implementations of both
setAttributes()
and
getAttributes()
can
be reused because they just operate over a collection and call the
getAttribute()
or
setAttribute()
method. In addition, the
invoke()
method is implemented in
a resource-generic manner.
The
invoke()
method uses its incoming parameter values to acquire a
java.
lang.reflect.Method
object from the
EJB
reference. After acquiring the
Method
instance, the
invoke()
method invokes it and returns its return value. It's impor-
tant to note what is left out of this method:
invoke()
blindly attempts to find a
method from the
EJB
that matches the parameters passed to it. However, what if
a management tools passes in a method name and description that is not part of
the MBean's
MBeanInfo
object, but is in fact implemented by the
EJB
? The
invoke()
implementation would allow MBean users to invoke methods not described by
the
MBeanInfo
object value (even if there is only a small chance of that happening).
Each method implemented from the
DynamicMBean
interface should check
requests against the MBean's management interface (described by the return
value of the
getMBeanInfo()
method). That is, each method should make sure
the requested operation or attribute is exposed in the manner in which the
incoming request wishes to use it. Dynamic MBeans must guarantee that their
implementation matches the management interface returned by their
getMBean-
Info()
method.
D
E
14.5.3
Running the workflow manager
To test this example, you need to deploy the
EJB
as you did in the previous
example. In addition, before this
EJB
is created in memory, you must have a
JMX
agent already running for the
EJB
to register its MBean. You can rewrite the
EJB