What is the importance of the Narrow class in RMI?

Showing Answers 1 - 3 of 3 Answers

Vijay Anandh

  • Nov 30th, 2005
 

PortableRemoteObject.narrow() method is used to cast the copy of the home object we get from the container.  Typically we find the home object by a jndi name

eg:Object obj =  context.lookup( "jndi-name of ejbhome" );

This "obj" comes from across the network to us.Therefore we need to cast it to the home object. What we should usually do for a cast is like this

HomeObject homeobj = ( HomeObject ) obj;

              where

  Was this answer useful?  Yes

Since client never talk to bean directly ,client get reference to component interface (EJBObject) by calling create() method on home interface

Client use JNDI to get reference to home interface, for that it first gets the InitialContext

Context ic=new InitialContext();   Object 0=ic.lookup("String");

Client use initial context to lookup bean home, but home stub returned  from JNDI lookup might not implement the home interface, To get the stub that is castable to home interface you have to narrow() the object you get from JNDI lookup ,    so to cast the object we get from JNDI lookup we use narrow() method. 

  Was this answer useful?  Yes

Nitin

  • Feb 13th, 2006
 

Objects returned by looking up a JNDI Name are returned by RMI-IIOP protocol. Since this protocol is language independent, objects returned by it should be typecasted using RMI-IIOP compliant method. Therefore we use PortableRemoteObject.narrow()

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions