• 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

Findings on implementing Local and Remote (RMI) interfaces

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, this is my first post... and my voucher is expiring in 2 mths

Just a finding I'd like to share about RMI and the local/remote interfaces problem.

I was thinking of a way where I could write a single local impl, and my remote impl would basically call the local impl to perform all the tasks (code reuse basically).

Based on the follow snippets:

When I run my server and client, I will always get an exception that says "$Proxy0 cannot be cast to xxx.Service".

After some trial and error, I made the following changes

Everything else works fine... and when I call getStatus() I will get "from xx.ServiceRemoteImpl" which is exactly what I want

My question is, why wouldn't my first approach work? Since ServiceRemoteImpl implements Remote and extends ServiceImpl (which implements Service) and therefore should be just what I need. Any RMI gurus out there that can provide a good answer?

As far as I'm concerned, the 2nd approach doesn't seems to break any SUN's rules and I'd prob use it for my assignment... however, it's all about learning and I'd like to find out what went wrong!

Thanks for viewing...
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ad,

Welcome to the JavaRanch!

Concerning your question: if you want to use your Service as a remote interface, it is a requirement to extend from java.rmi.Remote (more info about what you must do with regard to RMI can be found here).

Kind regards,
Roel
 
Ad Tan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:Concerning your question: if you want to use your Service as a remote interface, it is a requirement to extend from java.rmi.Remote (more info about what you must do with regard to RMI can be found here).



Sun states:
"A remote interface must at least extend, either directly or indirectly, the interface java.rmi.Remote."

In my original impl,
ServiceRemoteImpl extends ServiceImpl and implements Remote.

Hence, it indirectly implements the interface java.rmi.Remote.

That's why I didn't understand why it didn't work.

Ad
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ad,

According to the link I provided:

In RMI, a remote interface is an interface that declares a set of methods that may be invoked from a remote Java virtual machine.



So a remote interface is an interface and that interface must extend from java.rmi.Remote . In your example the remote interface implementation is implementing the java.rmi.Remote interface, but your remote interface isn't. And that's why it doesn't work: you violated one of the constraints.

I also experimented a bit with RMI, because I was unfamiliar with it. This thread can be found here.

Kind regards,
Roel
 
reply
    Bookmark Topic Watch Topic
  • New Topic