Java Reference
In-Depth Information
available for the duration of a unit of work and doesn't survive a server crash or shutdown.
A session bean can model any application logic functionality. There are three types of ses-
sion beans: stateful, stateless, and singleton .
A stateful session bean automatically saves the bean state between invocations from a
single, unique client without your having to write any additional code. The typical example
of a state-aware process is the shopping cart for a web merchant like Amazon. Stateful ses-
sion beans are either timed out or end their lifecycle when the client requests it. In contrast,
stateless session beans don't maintain any state and model application services that can be
completed in a single client invocation. You could build stateless session beans for imple-
menting business processes such as charging a credit card or checking a customer's credit
history. Singleton session beans maintain the state, are shared by all clients, and live for the
duration of the application. You could use a singleton bean for a discount processing com-
ponent since the business rules for applying discounts are usually fixed and shared across
all clients. Note that singleton beans are a new feature added in EJB 3.1.
A session bean can be invoked either locally or remotely using Java RMI. A stateless or
singleton session bean can also be exposed as a SOAP or REST web service.
1.2.2. Message-driven beans
Like session beans, message-driven beans (MDBs) process business logic. But MDBs are
different in one important way: clients never invoke MDB methods directly. Instead, MDBs
are triggered by messages sent to a messaging server, which enables sending asynchronous
messages between system components. Some typical examples of messaging servers are
HornetQ, ActiveMQ, IBM WebSphere MQ, SonicMQ, Oracle Advanced Queueing, and
TIBCO. MDBs are typically used for robust system integration and asynchronous process-
ing. An example of messaging is sending an inventory-restocking request from an auto-
mated retail system to a supply-chain management system. Don't worry too much about
messaging right now; we'll get to the details later in this topic.
1.3. Related specifications
EJB has two closely related specifications that we'll cover in this topic. The first is JPA,
which is the persistence standard for Java EE and CDI, and provides dependency injection
and context management services to all Java EE components including EJB.
Search WWH ::

Custom Search