10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A <strong>Java</strong> <strong>EE</strong> ApplicationThat Uses the JMS API with an Entity<br />

1. <strong>The</strong> HR department’s application client generates an employee ID for each new hire and<br />

then publishes a message (M1) containing the new hire’s name, employee ID, and position.<br />

<strong>The</strong> client then creates a temporary queue, ReplyQueue, with a message listener that waits<br />

for a reply to the message. (See “Creating Temporary Destinations” on page 935, for more<br />

information.)<br />

2. Two message-driven beans process each message: One bean, OfficeMDB, assigns the new<br />

hire’s office number, and the other bean, EquipmentMDB, assigns the new hire’s equipment.<br />

<strong>The</strong> first bean to process the message creates and persists an entity named SetupOffice,<br />

then calls a business method of the entity to store the information it has generated. <strong>The</strong><br />

second bean locates the existing entity and calls another business method to add its<br />

information.<br />

3. When both the office and the equipment have been assigned, the entity business method<br />

returns a value of true to the message-driven bean that called the method. <strong>The</strong><br />

message-driven bean then sends to the reply queue a message (M2) describing the<br />

assignments. <strong>The</strong>n it removes the entity. <strong>The</strong> application client’s message listener retrieves<br />

the information.<br />

Figure 32–2 illustrates the structure of this application. Of course, an actual HR application<br />

would have more components; other beans could set up payroll and benefits records, schedule<br />

orientation, and so on.<br />

Figure 32–2 assumes that OfficeMDB is the first message-driven bean to consume the message<br />

from the client. OfficeMDB then creates and persists the SetupOffice entity and stores the office<br />

information. EquipmentMDB then finds the entity, stores the equipment information, and learns<br />

that the entity has completed its work. EquipmentMDB then sends the message to the reply queue<br />

and removes the entity.<br />

Chapter 32 • <strong>Java</strong> <strong>EE</strong> Examples Using the JMS API 963

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!