bea.com | products | dev2dev | support | askBEA

Download Docs | Site Map | Glossary
Search

Programming BPM Client Apps

Disconnecting from the Process Engine

This section explains how to disconnect from the WebLogic Integration process engine. It includes the following topics:

- Removing Session EJB References

- Releasing Other Resources

Removing Session EJB References

Once you have completed all application tasks, you can remove the session EJB references to make the system space available for use by other EJBs.

The session EJB home and remote interfaces defined in the table API Session EJB Home and Remote Interfaces inherit methods from the javax.ejb.EJBHome and javax.ejb.EJBObject interfaces, respectively.

The following table defines the inherited methods that can be used to remove EJB references.

EJB Interface | Method | Purpose
--- | --- | ---
Home | public void remove(javax.ejb.Handle handle ) throws java.rmi.RemoteException, javax.ejb.RemoveException | Removes the EJB object associated with the specified handle.
public javax.ejb.HomeHandle getHomeHandle() throws java.rmi.RemoteException | Gets a handle for the home interface object.
Remote | public void remove() throws java.rmi.RemoteException, javax.ebj.RemoveException | Removes the EJB object.
public javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException | Gets the EJB home interface.
public javax.ejb.Handle getHandle() throws java.rmi.RemoteException | Gets a handle for the EJB object. This value can be used as the handle parameter in the Home interface remove() method, described previously in this table.

For example, the following code excerpt from the JSP worklist example shows how to remove the Worklist EJB reference, including the session variable. In this example, worklist represents the EJBObject reference to the Worklist EJB. The session variable is an HttpSession object in which you previously stored the worklist remote object reference.

>     Worklist worklist = null;
>     worklist = (Worklist)session.getValue("worklist");

>     if (worklist != null) {
>         try {
>     	worklist.remove();
>         } catch (Exception e) {
>         }

>         worklist = null;
>         session.removeValue("worklist");
>     }

For more information about the methods inherited by the home and remote interfaces, see the javax.ejb.EJBHome and javax.ejb.EJBObject Javadoc, respectively.

Releasing Other Resources

In addition to removing the session EJB references, you should perform the tasks described in the following sections:

- Stopping and Closing JMS Connections

- Closing the Context

Stopping and Closing JMS Connections

Typically, a JMS Provider allocates a significant amount of resources when it creates a connection. When a connection is no longer being used, you should close it to release the resources associated with it. A connection can be closed using the following javax.jms.Connection method:

>     public void close(
>     ) throws javax.jms.JMSException

For example, the following code provides an example of how to disconnect from JMS by closing the connection:

>     try {
>         tcon.close();
>     } catch (Exception e) {
>         	ExceptionHandler.reportException(e, this);
>       }
>       tcon = null;
>       tsession = null;
>       tsubscriber = null;
>     }

Once the connection is closed, the application sets the connection, session, and topic subscriber variables to null so that the garbage collector can free the resources used by these objects.

Closing the Context

To close the JNDI context resources (instead of waiting for them to be released automatically by the garbage collector), use the following javax.naming.Context method:

>     public void close() throws javax.naming.NamingException

For example, the following code closes the JNDI context resources:

>     try {
>         ctx.close();
>         {
>         catch(Exception exp)
>         {
>         }
>     }

For more information, see the javax.naming.Context Javadoc.