aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes What does the JNDI lookup return? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "What does the JNDI lookup return?" Watch "What does the JNDI lookup return?" New topic
Author

What does the JNDI lookup return?

Sat Nar
Ranch Hand

Joined: Oct 22, 2004
Posts: 83
Hi,
when we perform a JNDI lookup, does it return a reference to the Home interface or the reference to the class which implements the home interface which is created by the container during deployment?

Regards,
Sathya
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
The JNDI lookup returns a stub to the remote home object. This stub might not implement the home interface (as it might be an IIOP stub), so you must first narrow it and then cast it to the home interface. When we sometimes say that the home interface is returned, we actually mean that the stub returned from the lookup has been narrowed and cast to the home interface.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Sat Nar
Ranch Hand

Joined: Oct 22, 2004
Posts: 83
Hi,
the below is my understanding of the whole EJB functionality.Correct me if iam wrong.

Initially to start with, we define home interface,remote interface and a bean class.

First , we have to get a reference to Home interface.During deployment,the server automatically generates a class which implements this home interface(Let this class be denoted by A).During JNDI lookup,the object to this class is returned.

CustomerHome cust = Context.lookup("Customer");

Customer remote = cust.create();

Like above,during deployment,the server generates a class which implements the remote interface(let this class be denoted by B).When the create method is called,an object to this class is created and its reference is returned.Also an instance to the bean class is created either by calling the beans constructor or by taking the instance from the pool.So the remote variable contains the reference to the class generated by the server.

Now when a method is called,

remote.<method_name>

the control goes to the stub which performs marshalling.The stub transfers the data through network and the skeleton unmarshalls the arguements and calls the method in the class B.This inturn calls the actual bean implementation method.

This is my overall understanding of the working of EJB.Kindly correct me if iam wrong.

Regards,
Sathya
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Also an instance to the bean class is created either by calling the beans constructor or by taking the instance from the pool.

For a stateless session bean or entity bean, the instantiation is typically done on server startup when a pool of instances is created for each bean type. In other words, bean creation is not related to what the client does. However, if client requests require more instances than are available, the container may create more instances up to the maximimum limit specified for the bean type.

For a stateful session bean, it's different in that the bean instance creation is done upon invocation of the client's create() method. In other words, stateful session beans are not pooled but created on client requests.
Sat Nar
Ranch Hand

Joined: Oct 22, 2004
Posts: 83
Hi,
thanks for your reply.

In other words, stateful session beans are not pooled but created on client requests.


Can you kindly explain me why the instance creation for a stateful session bean happens only on the request and not pooled?

Regards,
Sathya
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by sathya Narayanan:
Hi,
thanks for your reply.



Can you kindly explain me why the instance creation for a stateful session bean happens only on the request and not pooled?

Regards,
Sathya


This is beacause the client could pass in some data during creation and so ejbCreate can have arguments.


Groovy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does the JNDI lookup return?