Wednesday, August 27, 2008

Identify correct and incorrect statements or examples about remote and local business interfaces for Session Beans SCBCD Exam Objective

Identify correct and incorrect statements or examples about remote and local business interfaces for Session Beans

For this objective, you need to know the obvious - that remote EJB clients go through a remote interface, and clients running on the same JVM as the EJB they are invoking can go through a local interface. Of course, there's nothing stopping a client on the same JVM using a remote interface, but it does seem a little excessive.

For Remote interfaces, they are used exactly the same way, regardless of whether the client is actually remote, or if the client is right there on the same JVM. This can't really be said for local EJB interfaces.

"Access to an enterprise bean through the local client view requires the collocation in the same JVM ofboth the local client and the enterprise bean that provides the local client view. The local client viewtherefore does not provide the location transparency provided by the remote client view."

What else?

3.0 EJBs do not need Home interfaces. Home interfaces are part of EJB 2.1, and not needed for EJB3, unless that is, you want to maintain backwards compatibility. Home interfaces are not required by 3.0 EJBs, but the Home interface is still there in the specification. We always want to try and maintain backwards compatability!

Page 41 of the EJB 3.0 Core Contracts pdf document states the following about Remote Interfaces:

"In EJB 3.0, a remote client accesses a session bean through the bean’s remote business interface. For a session bean client and component written to the EJB 2.1 and earlier APIs, the remote client accesses the session bean through the session bean’s remote home and remote component interfaces.

Compatibility Note: The EJB 2.1 and earlier API required that a remote client access the session bean by means of the session bean’s remote home and remote component interfaces. These interfaces remain available for use with EJB 3.0, and are described in Section 3.6.

The remote client view of an enterprise bean is location independent. A client running in the same JVM as a bean instance uses the same API to access the bean as a client running in a different JVM on the same or different machine.

The arguments and results of the methods of the remote business interface are
passed by value."

One thing to note about local interfaces is that they pass their arguments by reference, rather than by value as happens through the remote interface. This can really mess up a developer, especially if they are providing both a local and remote interface for an EJB. As such, developers should take the argument passing mechanism into account when they code their applications.

"The Bean Provider must be aware of the potential sharing of objects passed through local interfaces. In particular, the Bean Provider must be careful that the state of one enterprise bean is not assigned as the state of another. In general, the references that are passed across local interfaces cannot be used outside of the immediate call chain and must never be stored as part of the state of another enterprise bean. The Bean Provider must also exercise caution in determining which objects to pass across local interfaces. This caution applies particularly in
the case where there is a change in transaction or security context."

-pg 42 EJB Core Contracts Document

No comments: