Unformatted text preview:

EJB Prashant Lamba Niketu Parekh and William Pugh 1 Some notes Sun s j2ee ri fails in bad and mysterious ways under Java 1 5 The j2ee 1 3 1 implementation is certified under Java 1 3 Generally works under 1 4 2 What are EJB Some RMI Some software component technology terminology Ability to intercept calls and add systemlevel functionality Functionality that can be added transactions security activation passivation 3 Kinds of beans Entity beans represents thing in persistent store Message driven beans listeners we won t be talking much about these today Session beans stateless stateful 4 Bean clients Clients can only get references to session and entity beans Can create messages that are processed by message driven beans 5 Session Entity confusion Clients see same interfaces for both session and entities beans Some methods only make sense on entity beans some only on session beans Some methods have different semantics on entity beans 6 Entity beans An entity bean is backed by an entry in a persistent store removing an entity bean deletes the entry from the persistent store You can search for entity beans by primary key or there is even a query language 7 Stateful Session Beans Maintains state over a series of calls from a client Not shared between clients Can be almost silently dropped after timeout not for storing important data Cannot search for session bean 8 EJB Architecture Client VM Home Interface Home stub Component Interface EJBObject stub Component Interface EJBObject stub Interception happens here EJBObject Server VM Bean Bean EJBObject Interception happens here Home 9 Assumptions Initially we ll assume that all calls to EJB s are from remote machines at least via RMI assumption relaxed in EJB 2 0 we ll talk about it later Clients never get to talk directly to a bean would allow circumvention of security and transaction checks 10 Home sweet home Home interface allows beans to be created located and removed Factory design pattern I would have preferred factory to home as a naming convention But we are stuck with home User specifies interface only no code 11 Component interface Called remote interface in a lot of the literature made more sense when all client references were remote User specifies interface only no code 12 Responsibilities You provide Component interface Home interface Bean implementation class Container generates Home implementation and stubs EJBObject implementation and stubs 13 Bean doesn t implement component interface Typically the bean doesn t implement the component interface A bean is not an instance of a something that can be invoked by a client How do you know that a bean can handle all the methods supported by the interface tools 14 If this worries bothers you EnterpriseBean Remote EJBObject BookCart BookCartBusiness addBook removeBook SessionBean BookCartBean 15 Narrowing Normally in Java RMI you can just downcast a reference returned from a lookup e g RemotePortal p RemotePortal Naming lookup pAddress Not in EJB Context ic new InitialContext Object o ic lookup Advisor AdviceHome home AdviceHome PortableRemoteObject narrow o AdviceHome class 16 Deal with it This is ugly but necessary Deal with it RMI may be implemented with IIOP CORBA in which case downcast may actually have to do something If nothing needed it is cheap 17 EJBObject interface EJBHome Handle Object boolean void getEJBHome getHandle getPrimaryKey isIdentical EJBObject obj remove 18 EJBHome interface EJBMetaData HomeHandle void void getEJBMetaData getHomeHandle remove Handle handle remove Object primaryKey 19 Handles Handles are persistent references to EJBObjects Can be serialized passed between machines stored in Servlet sessions 20 isIdentical Used to determine whether two EJBObject stubs refer to the same bean Stateless session beans true if they come from the same home Stateful session beans false for any two distinct stubs Entity beans true if entities have same primary key and same home 21 Session Entity Bean Creation Home interface must have create methods EJB must have matching ejbCreate interfaces Stateless session beans should have only no argument create methods 22 Removal Removing an entity bean deletes the corresponding info from persistent store Removing a session bean says that you are done with it 23 Stateful Session Bean Lifecycle nowhere exception thrown garbage timeout create method in home invoked bean removed or times out method ready bean inactive call to bean passivated business method 24 Lifecycle notications nowhere exception thrown garbage constructor setSessionContext ejbCreate ejbRemove method ready ejbPassivate ejbActivate passivated business method 25 Stateless Session Beans No state that lasts longer than a single call from a client Only one call at a time on a stateless session bean Can have instance variables state that persist for the duration of one call Can keep resources debugging info caches Different invocations from a client can be routed to different beans 26 Local interfaces EJB2 0 adds local interfaces for components and homes extend EJBLocalHome and EJBLocalObject Local objects don t have handles Call by reference rather than deep copy Methods don t throw remote exception 27 Mix and Match No need for one bean to support both Local and Remote interfaces rather different Client of bean must know what it is getting 28


View Full Document

UMD CMSC 838P - EJB

Download EJB
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EJB and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EJB and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?