Unformatted text preview:

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


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?