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.

21.2 Expanding to EJBs475to its status. Those methods are defined in the bean class that the implementati<strong>on</strong>class extends. The classes <strong>on</strong>e extends to implement a bean are:• Sessi<strong>on</strong>Bean• EntityBean• MessageBeanPlease forgive us right now for admitting that we will not cover messagebeans in this book bey<strong>on</strong>d a brief descripti<strong>on</strong> in the next secti<strong>on</strong>. For details<strong>on</strong> message beans, take a look at Chapter 8 of Enterprise JavaBeans Comp<strong>on</strong>entArchitecture by Gail Anders<strong>on</strong> and Paul Anders<strong>on</strong> (ISBN 0-13-035571-2).Not all of the c<strong>on</strong>trol methods need to be implemented in all cases, butthe full set is not that large or difficult to understand. They corresp<strong>on</strong>d to important“life events” in lifetime of the bean. The primary events are: creati<strong>on</strong>,destructi<strong>on</strong>, passivati<strong>on</strong>, activati<strong>on</strong>, persist to DB, restore from DB, and c<strong>on</strong>textswitching.Creati<strong>on</strong>. A bean is created when its c<strong>on</strong>structor is called. As we shall learn,the calling of the c<strong>on</strong>structor has absolutely no c<strong>on</strong>necti<strong>on</strong> with a client request.For sessi<strong>on</strong> beans, the c<strong>on</strong>tainer maintains a pool of instances to handle clientrequests. For entity beans, a bean (most comm<strong>on</strong>ly) represents a database table,and the setEntityC<strong>on</strong>text() method is used to move that bean from row(instance) to row as needed.In practice, this usually means that a number of instances of the bean arecreated when the applicati<strong>on</strong> server is started. Additi<strong>on</strong>al instances are createdas the demand for this bean (number of clients, number of calls per unit time)increases.Destructi<strong>on</strong>. As you know, Java objects do not have explicit destructors,but when a bean instance is destroyed, an explicit method in the Bean class iscalled to permit shutdown operati<strong>on</strong>s to take place.This is quite distinct from activati<strong>on</strong> and passivati<strong>on</strong>. Activati<strong>on</strong> and passivati<strong>on</strong>are operati<strong>on</strong>s carried out when the applicati<strong>on</strong> server needs to shoveaside some Bean instances that may still be needed by clients in order to makeroom for an active request that requires more than the available systemresources.Passivati<strong>on</strong> and activati<strong>on</strong>. As we said above, passivati<strong>on</strong> involves thec<strong>on</strong>tainer asking the beans that are still potentially needed to step aside to allow

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

Saved successfully!

Ooh no, something went wrong!