Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / November 2003

Tip: Looking for answers? Try searching our database.

EJB and JBoss

Thread view: 
Giovanni - 08 Nov 2003 17:03 GMT
Hallo!
I have a stupid question:
I'm using Eclipse+Lomboz to create EJB and it creates a client this way:

CabinHomeRemote home=(CabinHomeRemote)jndiContext.lookup("CabinHomeRemote");
...

It works!
Now I'm reading a book about EJB and i read that i must write:
Object ref=(CabinHomeRemote)jndiContext.lookup("CabinHomeRemote");
CabinHomeRemote
home=(CabinHomeRemote)PortableRemoteObject.narrow(ref,CabinHomeRemote.class)
;
...

The first solution (without "narrow") it's correct?! If not, why it works
with JBoss?!

Thanx for any help!
Gio
Marek Lange - 10 Nov 2003 13:58 GMT
> Hallo!
> I have a stupid question:
[quoted text clipped - 13 lines]
> The first solution (without "narrow") it's correct?! If not, why it works
> with JBoss?!

The second solution uses a remote lookup. The first does a lookup "in
VM". That means, you just execute call by reference and not call by
value. It is possible with JBoss since client and EJB container are
coupled in the same VM (I assume the lookup is done from a web container
which is usually bundled with the ejb container in JBoss. If not, you
have to use the remote lookup syntax.).

-marek
Capitan Mutanda - 11 Nov 2003 16:40 GMT
> > Hallo!
> > I have a stupid question:
[quoted text clipped - 20 lines]
> which is usually bundled with the ejb container in JBoss. If not, you
> have to use the remote lookup syntax.).

I don't get your answer ... I'm learning EJBs just know... your explanation
holds if use use CabinLocalHome. In the second he is narrowing from
Object to CabinHomeRemote. My impression is that there is some code
missing..

cheers

cm
Marek Lange - 11 Nov 2003 19:25 GMT
Capitan Mutanda schrieb:
>>The second solution uses a remote lookup. The first does a lookup "in
>>VM". That means, you just execute call by reference and not call by
[quoted text clipped - 7 lines]
> Object to CabinHomeRemote. My impression is that there is some code
> missing..

I think JBoss is just optimizing the call. There is no need to use local
interfaces since JBoss recognizes in VM calls. I am not sure whether the
code will work in other app servers.

-marek
Johann Burkard - 11 Nov 2003 18:33 GMT
> CabinHomeRemote home=(CabinHomeRemote)jndiContext.lookup("CabinHomeRemote");
> ....

[...]

> Object ref=(CabinHomeRemote)jndiContext.lookup("CabinHomeRemote");
> CabinHomeRemote
> home=(CabinHomeRemote)PortableRemoteObject.narrow(ref,CabinHomeRemote.class)
> ;

[...]

> The first solution (without "narrow") it's correct?! If not, why it works
> with JBoss?!

From what they say, the first version may work, but it's recommended to
use version 2 for remote Objects. I heard that JBoss optimizes these
calls if your code and the Beans run in one VM.

When you look in the PortableRemoteObject implementation [1], you can
see that it's more or less a simple type check:

    public java.lang.Object narrow ( java.lang.Object narrowFrom,
                                            java.lang.Class narrowTo)
    throws ClassCastException {

[...]

    Class narrowFromClass  = narrowFrom.getClass();

        try {

            // Will a cast work?

            if (narrowTo.isAssignableFrom(narrowFromClass)) {

                // Yep, so we're done...

                result = narrowFrom;

[1] com.sun.corba.se.internal.javax.rmi.PortableRemoteObject

Johann
Signature

ich bin mir zimlich sicher wo ich bin du treumer.
("Bernd P." in dag° und in <b1mjh6$14dal3$1@ID-156972.news.dfncis.de>)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.