13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

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.

478Chapter 21Introducti<strong>on</strong> to Enterprise JavaBeanstime that it is free without requiring any distributi<strong>on</strong> of client informati<strong>on</strong>between Bean instances.From the client’s perspective, the client can c<strong>on</strong>nect to any instance of theBean <strong>on</strong> any server at any time to get the same work d<strong>on</strong>e.Stateful Sessi<strong>on</strong> BeansWhat they are. A stateful sessi<strong>on</strong> bean is <strong>on</strong>e that remembers its client betweenmethod invocati<strong>on</strong>s. It maintains some informati<strong>on</strong> between calls froma client. Because of this, a given Bean instance can <strong>on</strong>ly handle <strong>on</strong>e client at atime, and if an instance is to be switched between clients, the informati<strong>on</strong>about the previous client must be saved so that the client’s sessi<strong>on</strong> may berestored later.An applicati<strong>on</strong> that is designed around stateful sessi<strong>on</strong> beans will generallyrequire more resources than <strong>on</strong>e designed around stateless sessi<strong>on</strong> beans(described above) because each active client requires a dedicated instance ofthe Bean.Why you would use them. We think we’ve beaten the issue of the advantagesof stateless beans into the ground. But what are the advantages of astateful bean?Many types of client interacti<strong>on</strong> require the bean to “remember” somethingabout the client. The classic (and, by now, almost cliché) example is aWeb-based shopping cart applicati<strong>on</strong>. The remote interface for a statefulShoppingCart EJB might look something like this:createCartCreates a new shopping cart for the customer.addItemAdds an item to the shopping cart.delItemRemoves an item from the shopping cart.purchaseCartProcesses the cart; charges the credit card; generates pick list, shipping list,and invoice; discards cart.aband<strong>on</strong>CartDiscards the cart.

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

Saved successfully!

Ooh no, something went wrong!