< Zurück | Inhalt | Weiter >

22.2.4 Summarizing the Pieces

With these three pieces—the session bean, the remote interface, and the home interface—we can see the structure of the key pieces of an EJB. Let’s review what we have:


image

image

Application object


image

Money MoneyHome MoneyBean

Extends/implements


EJBObject EJBHome SessionBean

Talked about as

remote interface home interface

the implementation


22.2.5 EJBLocalHome and EJBLocalObject

When the session or entity bean is going to be referenced by application code that resides on the same host as the bean, there are variations on the home and remote interfaces that allow for more efficient execution. When you know that the beans are local to this host, you should use a local interface (Example 22.4)


image

Example 22.4 Sample local interface

package com.jadol.budgetpro; import javax.ejb.*;

import java.rmi.*;


/**

* Local Interface for the Money EJB

*/

public interface MoneyLocal

extends EJBLocalObject

{

// the methods which we will call


} // interface MoneyLocal


image


image

Example 22.5 Sample local home interface

package com.jadol.budgetpro; import javax.ejb.*;

import java.rmi.*;


/**

* Local Home Interface

*/

public interface MoneyLocalHome

extends EJBLocalHome

{

public MoneyLocal create()

throws CreateException;


} // interface MoneyLocalHome


image


and a local home interface (Example 22.5). The local interface is in place of the remote interface and extends EJBLocalObject. The local home interface is in place of the remote home interface and extends EJBLocalHome.

Why bother? Well, there’s no need to marshal and unmarshal all that data if the calls are staying on the same host. This saves execution time. Perhaps more importantly, since the arguments don’t have to be marshaled and


unmarshaled, they don’t have to be serializable. For some applications, this is the only way that they can use beans.

Finally, keep in mind that the choice of local versus remote interfaces is not necessarily an either-or choice. For our session bean we have defined both kinds of interfaces. Then the deployment can determine which one will be used.