CONTENTS | PREV | NEXT | INDEX Designing Enterprise Applications
with the J2EETM Platform, Second Edition



5.3 Remote and Local Client Views

The EJB 2.0 specification introduces a local client view for session and entity beans, in addition to preserving the remote client view defined by the EJB 1.1 specification. As described in the previous sections, a session or entity bean can implement a local home interface and local component interface instead of (or in addition to) a remote home interface and remote component interface.

An enterprise bean defines a remote client view when it is designed for use in a distributed environment; that is, when its clients may potentially reside in a different JVM. Each method call on a bean's remote home or component interface results in a remote method invocation. Although necessary for distributed systems, remote method invocations have a certain amount of network overhead and can have performance limitations. In addition, the overhead of a remote invocation occurs even if the client and the bean are located on the same JVM. This can be particularly problematic in situations that require fine-grained access to objects. (See Section 5.7.3 on page 158 for a more complete discussion of how to handle fine-grained access.) While these limitations are unavoidable for distributed systems, proper design can reduce their impact.

Use of a local client view avoids the performance overhead of remote method invocation. To use a local client view, the enterprise bean and its client must be guaranteed to be located on the same JVM. By implementing a local home interface and local component interface, co-located enterprise beans can make direct, local method calls on the methods of other beans and avoid the remote invocation overhead. It is thus feasible to implement fine-grained access between beans using local interfaces.


5.3.1 Guidelines for Using Local or Remote Client Views

In certain situations it is preferable to use a local client view (local home and component interfaces) for an enterprise bean. In other situations, a remote client view (remote home and component interfaces) is more appropriate. Keep in mind that most of these considerations apply to session beans as well as entity beans, because both can implement local and remote client views.

The use of local interfaces for enterprise beans may be better suited to some applications. Consider using local interfaces for session and entity beans under these circumstances:

An entity bean that uses local interfaces is referred to as a lightweight entity bean because it avoids the performance costs of remote interfaces.


5.3.2 Entity Beans and Local Client Views

An entity bean is generally used with a local view. If the application is such that a remote view is necessary, the developer can use a session bean with a remote client view as a facade to entity beans with local views. See Section 5.7.2 on page 157 for more information.

Local interfaces offer other advantages for entity beans. Local interfaces enable entity beans with container-managed persistence to participate in container-managed relationships with other entity beans. With container-managed relationships, the EJB container manages the persistent relationships between entity beans, much like it manages the persistent state of entity beans. Container-managed relationships are described further in Section 5.4.2.2 on page 146.



CONTENTS | PREV | NEXT | INDEX
Copyright © 2002 Sun Microsystems, Inc. All Rights Reserved.