aspose file tools*
The moose likes Distributed Java and the fly likes RMI and RemoteException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI and RemoteException" Watch "RMI and RemoteException" New topic
Author

RMI and RemoteException

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

Hi,

A little bit playing around with RMI. I have the following (simple) interface:


and an implementation that's even simpler:


I was wondering if it's possible to work with RMI but in your implementation get rid of the RemoteException, so something like:


and an implementation:

so you could use the same interface for a local implementation, another network technology,... or are you stuck on this RemoteException?

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Oscar Costa
Ranch Hand

Joined: Feb 05, 2009
Posts: 31

Hello Roel,

You can use an application exception too. But you need to throw the RemoteException. This exception is used when a remote method invocation fails...

See at http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-objmodel5.html


"Do or do not... there is no try!" - Jedi Master Yoda
> SCJP 5 : SCWCD 5 : SCBCD 5 <
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5408
    
  13

Oscar,

Thanks for your quick reply.

after some experimenting following conclusions:
- PowerService without "extends Remote" --> ClassCastException when trying to run the client
- method from PowerService without "throws RemoteException" --> RemoteException("remote object implements illegal remote interface") when trying to run the server

so it's required to add RemoteException to all of your method signatures in your interface. The best you can do to depend as little to rmi as possible, is having something like this:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI and RemoteException