EJB and JBoss - Java

This is a discussion on EJB and JBoss - Java ; 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"); ...

+ Reply to Thread
Results 1 to 5 of 5

EJB and JBoss

  1. Default EJB and JBoss

    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





  2. Default Re: EJB and JBoss

    Giovanni wrote:

    > 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?!


    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


  3. Default Re: EJB and JBoss

    Marek Lange <marek.lange@web.de> wrote in message news:<boo55u$uvi$07$1@news.t-online.com>...
    > Giovanni wrote:
    >
    > > 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?!

    >
    > 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.).


    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

  4. Default Re: EJB and JBoss

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


  5. Default Re: EJB and JBoss

    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
    >>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.).

    >
    > 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..


    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


+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 08-16-2009, 01:56 PM
  2. [JBOSS] Can't connect Client to remote JBoss 3.2.2 server
    By Application Development in forum Java
    Replies: 9
    Last Post: 04-22-2005, 06:21 AM
  3. EJB and JBOSS
    By Application Development in forum Java
    Replies: 0
    Last Post: 04-29-2004, 12:17 PM
  4. EJB and JBOSS
    By Application Development in forum Java
    Replies: 0
    Last Post: 04-29-2004, 12:08 PM
  5. JBoss ignoring override of max-bean-age in jboss.xml
    By Application Development in forum Java
    Replies: 0
    Last Post: 12-15-2003, 05:02 AM