How do I reference a Local Home interface?

D

David

I am struggling to understand EJBs, basically I have got an EJB called
Stateless2 and the following source files...

Stateless2Bean.java (the actual EJB)
Stateless2.java (EJBObject)
Stateless2Home.java (EJBHome)
Stateless2Local.java (EJBLocalObject)
Stateless2LocalHome.java (EJBLocalHome)

....now I understand I can just do a JNDI lookup for the EJBHome
(ejb/Stateless2Home) and I get the (remote) home interface and then
call the create() to get the (remote) object interface (ie with the
business logic methods)

This all works fine, but if my understanding is correct then all calls
to these objects go to the network layer (even if the EJB and servlet
are in the same JVM) and so are relatively inefficient.

....thats where the (local) Home and (local) object interfaces comes
in, they work in the same way, but make local calls and so are more
efficient.

The problem is that I cant figure out how to call them! Do I just do a
JNDI lookup for it, if so then what is the reference?

I have lauched the Universal Test client (in WSAD) and can browse the
JNDI tree and see ejb/Stateless2Home etc, I can also so a section
called [local EJB Beans] which expands to ejb/Stateless2Home which if
a look into it this is actually the (local) Home, but I cant figure
out what the JNDI name is?

Any help grately appreciated.

David Bevan

http://www.davidbevan.co.uk
http://www.websphereusergroup.org.uk
 
J

John C. Bollinger

David said:
I am struggling to understand EJBs, basically I have got an EJB called
Stateless2 and the following source files...

Stateless2Bean.java (the actual EJB)
Stateless2.java (EJBObject)
Stateless2Home.java (EJBHome)
Stateless2Local.java (EJBLocalObject)
Stateless2LocalHome.java (EJBLocalHome)

...now I understand I can just do a JNDI lookup for the EJBHome
(ejb/Stateless2Home) and I get the (remote) home interface and then
call the create() to get the (remote) object interface (ie with the
business logic methods)

This all works fine, but if my understanding is correct then all calls
to these objects go to the network layer (even if the EJB and servlet
are in the same JVM) and so are relatively inefficient.

They may or may not actually go to the network layer, but they do obey
the semantics for remote method invocations. Among other things, those
semantics involve creating copies of all the outbound arguments and the
inbound return values.
...thats where the (local) Home and (local) object interfaces comes
in, they work in the same way, but make local calls and so are more
efficient.

As you say, local method invocations are more efficient in every J2EE
implementation I have any knowledge of. This is in part because they
have standard Java method invocation semantics (specifically, reference
passing semantics).
The problem is that I cant figure out how to call them! Do I just do a
JNDI lookup for it, if so then what is the reference?

You do a JNDI lookup for the EJBLocalHome object, and use it to obtain
an EJBLocalObject instance. This works very much the same as a remote
EJB lookup, although you are not required to use
PortableRemoteObject.narrow() on the EJB instance (but you may do if you
want to). The JNDI name to which the local home object is bound is
configured with the rest of the bean's deployment information, much the
same way that the name of the [remote] home object is configured.


John Bollinger
(e-mail address removed)
 
H

Henrik Sjostrand

John C. Bollinger said:
David said:
I am struggling to understand EJBs, basically I have got an EJB called
Stateless2 and the following source files...
[snip]

The problem is that I cant figure out how to call them! Do I just do a
JNDI lookup for it, if so then what is the reference?

You do a JNDI lookup for the EJBLocalHome object, and use it to obtain
an EJBLocalObject instance. This works very much the same as a remote
EJB lookup, although you are not required to use
PortableRemoteObject.narrow() on the EJB instance (but you may do if you
want to). The JNDI name to which the local home object is bound is
configured with the rest of the bean's deployment information, much the
same way that the name of the [remote] home object is configured.


John Bollinger
(e-mail address removed)

You need to set up an EJB reference to find your EJB's Local Home
Interfaces. Take a look in the EJB 2.0 Redbook for details on how to
do it (it's easy!):
http://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246819.html?Open

/Henrik Sjöstrand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top