background image

Defining Client Access with Interfaces

<< What Is a Message-Driven Bean | Local Clients >>
<< What Is a Message-Driven Bean | Local Clients >>

Defining Client Access with Interfaces

is rolled back, the message will be redelivered. For more information, see
Chapter 23, "A
Message-Driven Bean Example"
and
Chapter 33, "Transactions."
When to Use Message-Driven Beans
Session beans allow you to send JMS messages and to receive them synchronously, but not
asynchronously. To avoid tying up server resources, do not to use blocking synchronous
receives in a server-side component, and in general JMS messages should not be sent or
received synchronously. To receive messages asynchronously, use a message-driven bean.
Defining Client Access with Interfaces
The material in this section applies only to session beans and not to message-driven beans.
Because they have a different programming model, message-driven beans do not have
interfaces that define client access.
A client can access a session bean only through the methods defined in the bean's business
interface. The business interface defines the client's view of a bean. All other aspects of the bean
(method implementations and deployment settings) are hidden from the client.
Well-designed interfaces simplify the development and maintenance of Java EE applications.
Not only do clean interfaces shield the clients from any complexities in the EJB tier, but they
also allow the beans to change internally without affecting the clients. For example, if you
change a session bean from a stateless to a stateful session bean, you won't have to alter the
client code. But if you were to change the method definitions in the interfaces, then you might
have to modify the client code as well. Therefore, it is important that you design the interfaces
carefully to isolate your clients from possible changes in the beans.
Session beans can have more than one business interface. Session beans should, but are not
required to, implement their business interface or interfaces.
When you design a Java EE application, one of the first decisions you make is the type of client
access allowed by the enterprise beans: remote, local, or web service.
Remote Clients
A remote client of an enterprise bean has the following traits:
It can run on a different machine and a different Java virtual machine (JVM) than the
enterprise bean it accesses. (It is not required to run on a different JVM.)
It can be a web component, an application client, or another enterprise bean.
To a remote client, the location of the enterprise bean is transparent.
Defining Client Access with Interfaces
The Java EE 5 Tutorial · September 2007
636