• 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

Java RMI

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please excuse me if i am asking the obvious or something which has been previously discussed. I searched a little for this.... but i didnot know what exactly to search. I will keep searching on google to find out if I get an answer.

I have been exposed to RMI for the first time after learning Languages. One thing felt a little striking.



Consider the implementation




Now the client








I realized that the 2nd optioin is the right option. However, if I use the first, it gives me an error at runtime(Invalid cast). Now as far as I know, since the abstract interface method sayHello is defined only in the RMIImplementation class. So effectively any class which is returned by Naming.lookup will be a subclass of RMIImplementation and thus of RMIInterface.
If this is the case, why is there a problem in the casting?

What exacatly is the type of the returned object if it is not RMIImplementation but still is a type of RMIInterface
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please assume minor mistakes are taken care of before compiling. and the boilerplate code is correct
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be a class created automatically by the JVM for this purpose; it won't be related to "RMIImplementation" in any way. In fact, the client program doesn't need the RMIImplementation class file to be on its class path.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, I'll move this to our Distributed Java forum - the place for RMI on JavaRanch.

Gaurav Raje wrote:I realized that the 2nd optioin is the right option. However, if I use the first, it gives me an error at runtime(Invalid cast). Now as far as I know, since the abstract interface method sayHello is defined only in the RMIImplementation class. So effectively any class which is returned by Naming.lookup will be a subclass of RMIImplementation and thus of RMIInterface.
If this is the case, why is there a problem in the casting?

What exacatly is the type of the returned object if it is not RMIImplementation but still is a type of RMIInterface


It's RMIImplementation_Stub. The rmic compiler creates two helper classes for your RMIImplementation class: RMIImplementation_Skel and RMIImplementation_Stub. These two wrap around your RMIImplementation class to handle the communication. The Stub class also implements the interface, and that's why casting to the interface works and casting to the original class doesn't.
You can verify as such:
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply....
I did check the class of the returned object. But i always thought it was still a subclass of the implementation. Hence was confused...

Thanks for clearing my doubt.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic