aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Findings on implementing Local and Remote (RMI) interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Findings on implementing Local and Remote (RMI) interfaces" Watch "Findings on implementing Local and Remote (RMI) interfaces" New topic
Author

Findings on implementing Local and Remote (RMI) interfaces

Ad Tan
Greenhorn

Joined: Oct 30, 2009
Posts: 22
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...
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Ad Tan
Greenhorn

Joined: Oct 30, 2009
Posts: 22
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
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Findings on implementing Local and Remote (RMI) interfaces