Java Reference
In-Depth Information
D
At some point, an EJB client will complete this workflow or abort it and must
remove the EJB from existence. It does so by calling the ejbRemove() method. This
method does two things. First, it invokes the removeEJBMBean() method, which
unregisters the MBean that was exposing the EJB for management. This way, even
if the remaining operations of this method fail, the MBean will not exist. The sec-
ond task for ejbRemove() is to delete its persistent state from the database.
These next few methods are the reason you wrote this Enterprise JavaBean. The
installEJBMBean() EJB method creates and initializes a WorkflowManager MBean
to expose the remote interface methods from this EJB . To do this, the EJB must
create an instance of the MBean. It does so by calling the constructor that takes
two arguments: a String value acting as the clientid value that initialized the
EJB , and a String value that represents the JNDI name used to look up the home
interface of this EJB . Once the WorkflowManager MBean looks up the home inter-
face, it can use the clientid value to find the appropriate WorkflowBean EJB to
expose for management.
After creating a WorkflowManager MBean instance, the EJB must register it on
a MBean server. How to acquire an MBean server depends on the application
server containing your application. To encapsulate the MBean server discovery,
the EJB provides a getMBeanServer() method, which stubs out the code necessary
to acquire the MBean server.
After acquiring an MBeanServer instance, the EJB must register its new Work-
flowManager MBean. Recall that the ObjectName class is a JMX class that acts as a
key on the MBean server to a particular MBean instance. It contains a domain
name and a property list that makes it unique across the MBeanServer instance. To
create an instance of the ObjectName class, you use the constructor that accepts a
domain name and a single key and value argument. Now that you have an MBean
instance, an MBeanServer instance, and an ObjectName instance, you can register
the MBean by invoking the MBean server's registerMBean() method.
The ejbRemove() method invokes the removeEJBMBean() method before it deletes
its state from the database. The removeEJBMBean() method looks up an instance of
the MBeanServer (just like the install method) by invoking the getMBeanServer()
method. It also creates an instance of ObjectName that represents the EJB 's MBean,
and calls the unregisterMBean() method to remove it.
E
F
14.5.2
Constructing the WorkflowManager MBean
Let's recap what you have accomplished. You have created an entity bean that rep-
resents a client's state as it moves through a business workflow. The Workflow EJB ,
Search WWH ::




Custom Search