Sunday, September 30, 2007

images



EJB_Made_Easy_Index

1) Conceptual Learning of beans

2) All_in_one_table_of_EJBs

All_in_one_table

This Table is very important in the sense that it explains all the methods, how /when they are invoked and what are the back ground happenings behind the method invocation etc.,
Understanding each row is very important

Note : A few errors might have crept in.. If there are any ,they would be corrected so please always check the newest page ....


Stateless

Stateful

Entity

Pool Creation

(pool of beans is always non-dedicated beans)

Yes

1.call setSessionContext(<..>),

Followed by ejbCreate().

If pooling is supported every bean must be taken from pool

No

Yes

1.call setEntityContext(<..>)

*does not call ejbCreate(<..>) because parameterized create invocation makes a bean dedicated

If pooling is supported every bean must be taken from pool for even getting dedicated bean .. if not passivate some other bean

Dedicated Beans?

No

  1. picks one bean from pool ,invokes service method sends back to pool

* as session beans don’t need dedicated bean

Yes

  1. instantiated on demand and initialized with specific client data by calling ejbCreate(<..>)

or

  1. if total number of instantiated beans reached limit, passivate an inactive dedicated bean , reset and reinitialize for the present client.

______________________

Methods on dedicated :

1.all service methods

2.ejbPassivate();(container calls, not client)

Yes

1. picks one bean from pool ,invokes ejbCreate(<..>) ,

Makes bean dedicated

Or

2.There is no free bean in pool , so

, passivate an inactive dedicated bean , reset and reinitialize for the present client.

______________________

Methods on dedicated :

1.all service methods

2.ejbStore() and ejbPassivate(();(container calls ,not client)

Methods on dedicated :

None

Non- Dedicated beans

Yes

1.picks one bean from pool ,invokes service method sends back to pool

* as session beans don’t need dedicated bean

**Methods on Non-dedicated : all service methods

SentBack to Pool ?

Yes

No ..

For a small period of time, a non-dedicated bean exists ..

Some passive bean was passivated ,becomes non dedicated but immediately becomes dedicated by swapping a client specific data from persistent storage

Into bean

** there is a diff between entity bean persistence and stateful bean persistence..

Swapping means cut and paste , cut from persistent storage

And paste it to your stateful bean ..

So when remove() is called on stateful , bean ,bean instance is destroyed, session data is lost.., (cant be retrieved again)

Yes

1.picks one bean from pool ,invokes finder /home service/ejbRemove method sends back to pool

*Home service method is a special method which operates on entire table of DB rather than specific row..

If it executes ejbCreate(<..>) bean become dedicated

SentBack to Pool ?

Yes and No

**Methods on Non-dedicated which send bean back to pool :

1.finder methods

2.Home Service method,ejbHome..(..)

3.ejbRemove()

**Methods on Non-dedicated which don’t send bean back to pool :

1.ejbCreate(<..>)

ejbStore()

NA

NA

1.to synchronize data b/w bean and DB

or

2.called before passivation

Called on : Dedicated

ejbLoad()

NA

NA

1.to synchronize data b/w bean and DB

or

2.after activation :

In this case , the bean is for a brief period in non-dedicated state so use ctx.getPrimaryKey();

ejbRemove()

Destroys bean

Object is GCed as container nullifies the reference to bean

**can be Called by container to reduce pool size

Or

when client calls remove() on home or EJBObjects,

The container may/may not call ejbRemove(); as it may be pooled for reusing

Bean will be destroyed so session data is destroyed

*client can call remove() on home or EJBObjects

To logout his session

Strictly speaking container has to call ejbRemove() in this case, but due to container crashes ,may not be called

Or

*container may call when session expires

** takes a non-dedicated beansideNotes1 from Pool ,

Removes DB record

Goes back to pool

*only client can call remove() on home or EJBObjects

** as a non-dedicated bean services this, use ctx.getPrimaryKey();

ejbPostCreate(<..>)

NA

NA

Called after ejbCreate(<..>)

ejbPassivate()

NA

close resources

** don’t write persistence logic here

Container may use java serialization to persist

close resources

** Don’t write persistence logic here

Use ejbStore()

ejbStore() call precedes ejbPassivate()

ejbActivate()

NA

open resources

** don’t write persistence logic here

Container may use java serialization to persist

open resources

** Don’t write persistence logic here

Use ejbLoad()

ejbActivate() precedes ejbLoad();

Finder methods

NA

NA

Go-back bean from pool taken ,returns single PK/Collection of PKs, goes back to pool

*Container constructs new dedicated beans(takes beans from pool) ,associates them EJBObjects,

Sends back Collection of EJBObject references /single EJBObject references

*Please don’t initialize bean’s state in finder method..,

Finder method should not make a bean dedicated

Learn_easy_EJB

This Section of my blog is meant for those who either worked with EJBs or have a little idea about Enterprise Java Beans.
Novice Users need something more to start with rather than diving to this section..
------------------------------>
Let us start.. To simplify the understanding i have used my own terminology to explain the concepts. Please Note that these terms are not part of specifications from Sun..
------------------------------->

For the simplicity of explanation of EJBs let us categorize beans as

Dedicated EJBean and Random EJBean..

B.1.Dedicated EJBean is one which gives services to a specific client,It means that the dedicated EJBean must be a specific one to the client..,

B.1.1.How are dedicated beans created ?

Dedicated are required only for stateful session and entity beans

So They can be taken from pool and initialized or new bean may be created & initialized on demand or something else is passivated and reinitialized to become dedicated to the present client

Examples:

Entity :

a) beans can be taken from pool and initialized (entity beans) to make them dedicated

Stateful :

A)if it’s a new request for the first time and If the limit for the number of stateful beans is not reached yet new stateful bean is instantiated and initialized with client session data

b) not a new request but the dedicated object for that client is not found (might have been passivated) ,one of the in-memory dedicated beans(for diff clients) is passivated and its reused to initialize a new dedicated bean ( stateful session beans)

B.2. Random(non dedicated) EJBean is one which is picked up on demand from a BEAN POOL to service a client request , and sent back to pool againimp .. that means there are certain type of requests for which Dedicate EJBean is not necessary …

#############################################################

Section C :

Which Beans are necessary in different conditions??

a) Stateless Session Beans ???

Methods of stateless session beans don’t depend on client state data Nor need client data to provide service..

So Any Random EJBean(Stateless Session Beans) can provide a service

Thus solution for this ?

Pick up a random bean from POOL , execute method(providng service)

The random bean goes back to pool .(may be picked up to service another client request)

b) Stateful Session Beans ???

There Is no concept of pooling at all.. (virtual Pooling)

No question of Random picking..

Each service method must be executed on a dedicated stateful bean

Check section A.

Do they require any random beans? No

c) Entity Beans ???

Pooling concept is present ..

Because there are certain methods which can be executed on non-dedicated beans.

Eg:

-- findByPrimaryKey(<..>) Is called on a homeobject.

--Container picks a random(non dedicated) bean from pool , executes

--ejbFindByPrimaryKey(<..>) , the method gives back PK class and

--The random bean goes back to pool

--container based on PK , creates a new dedicated bean(picks a random one from pool ), creates EJBObject ,gives back to client

Dedicate beans are needed ? yes

--To service business methods on data like getting setting manipulating etc.,

#######################################################

Section A :

For simplicity let us categorize methods as create,find and service methods

A.1.Create method à for initializing a bean with either a specific client session data/specific business data or none of them

Note : create methods don’t create or instantiate bean instances, they are for initializing an already instantiated bean

ü Whenever a parameterized create is called , then that bean will become dedicated..

ü ejbCreate() doesn’t make a bean dedicated as it has no parameters

ü ejbCreate(<..>) makes the bean dedicated

A.2,Service Method : these methods give services like setting/getting or other business process logic

Note : service methods of stateless session Beans are not specific to any client ,so they don’t depend on client data/session data

A.3.Find methods :

They are not for initializing with the help of parameters ,

They are just for finding ..

You can consider these methods are like service methods of stateless session beans .

After Find methods bean is not dedicated it can be sent back to pool