Java Reference
In-Depth Information
when initialized, creates a
WorkflowManager
MBean to expose the
EJB
's remote
interface for management. In addition, when the
EJB
is removed, it removes its
associated MBean.
At this point, all you have left to do is to create the
WorkflowManager
class.
The
WorkflowManager
class implements the Dynamic MBean for workflow man-
agement. Because the
EJB
's remote interface declares the exposed operations,
it would be simple to turn that interface into the MBean interface of a Stan-
dard MBean.
However, if you changed the remote interface, you would invalidate all the
interfaces to the MBean as well. In addition, what if you are creating MBeans for
previously created
EJB
s? The Standard MBean does not provide a good way to
“upgrade” if its management interface needs to change.
WorkflowManager code
The code in listing 14.10 is the implementation of the
WorkflowManager
Dynamic
MBean. This MBean will expose the methods that were declared in the
EJB
's
remote interface. Specifically, it exposes the
advanceState()
operation and the
State
attribute.
Listing 14.10
WorkflowManager.java
package jmxbook.ch14;
import javax.management.*;
import javax.naming.*;
import java.rmi.*;
import java.lang.reflect.*;
public class WorkflowManager implements DynamicMBean
{
private String clientID = null;
private Workflow ejb = null;
public WorkflowManager( String clientID, String JNDIName )
throws Exception
{
this.clientID = clientID;
WorkflowHome home = lookUpHome();
ejb = ( Workflow ) home.findByPrimaryKey( clientID );
}
B
Construct
MBean
C
Create
management
interface
public MBeanInfo getMBeanInfo()
{
try
{
MBeanAttributeInfo[] atts = new MBeanAttributeInfo[ 1 ];
atts[0] =