• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PortableRemoteObject.narrow()

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Little help please,

I understand that when using remote references (stubs) to EJB's they must be narrowed in the following mannor:

InitialContext ctx = new InitialContext();
Object obj = ctx.lookup(SomeObject);
SpecificObject so = (SpecificObject) PortableRemoteObject.narrow(obj, SpecificObject.class);

However, do you also have to use PortableRemoteObject.narrow() when obtaining a datasource, or some other kind of object?

Thanks in advance!
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not required

In case of Data Source and LocalHome
 
Ravi Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

Why is it not required when obtaining a datasource but it is for remote home interfaces obtained using ctx.lookup()?
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EJB spec requires the RMI-IIOP to conform with CORBA standard and Corba standard supports languages (besides C++ or Java) which does not support direct casting. So, in order to be compliant with RMI-IIOP, if one has to cast a remote reference (which may not be a direct subclass of EJBHome) to a subclass of EJBHome, (s)he has to use PortableRemoteObject.narrow method to do that. This is required as the application server JVM may obtain the reference to the home over RMI-IIOP protocol and the actual implementation of the Home object may reside in an environment outside this JVM.

But, in case of situations like pooled connections or local home, the implemented object reside in the same JVM, which means you can always use downcasting (polymorphism) and use a direct cast to your home class type.

Hope this helps, but I am sure there will be someone who can better explain this.
[ October 04, 2004: Message edited by: Susanta Chatterjee ]
 
Ravi Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

Things are slightly clearer but I still am slightly confused.

I thought you could obtain a datasource from a remote application server?

If this was the case, would you have to do the following?

PortableRemoteObject.narrow(ref, javax.sql.Datasource.class)
 
All of the following truths are shameless lies. But what about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic