• 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

B&S Question on RMI

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to implement an Remote Interface for this application. My interface only is throwing RecordNotFoundException. If I have to expose any method thru the RMI it should actually throw RemoteException. When I add a throws clause to the class which implements the interface, I get an error saying that the exception is not part of the interface. how should I go about this ?

Thanks

- Harjit
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remote methods can only throw RemoteExceptions.

You then have 2 options:
- Wrap your exception in a RemoteException. (Use 'Cause' in the RemoteException)
- For your own Exceptions, you can let them extend the RemoteException, which will allow your class to throw them without breaching the interface.

Hope that helped.
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll add that although both of Peter's options are perfectly valid, the first one is very much preferred. (Ab)using RemoteExceptions for an interface that is not necessarily related to RMI is bad style in my opinion.
 
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I follow what you are saying. How will I be able to use option 1 with the following

I have a interface which has this method

public String[] readRecord(long recNo) throws RecordNotFoundException;


Thanks

- Harjit
[ November 21, 2007: Message edited by: Harjit Singh ]
 
Ranch Hand
Posts: 92
Android Eclipse IDE Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Remote methods can only throw RemoteExceptions.



Completly wrong. Remote methods must declare to throw the RemoteException because of the RMI transport implementation. Other than that they can throw any other Exception, cause we all know they are Serializable, didn't we? So no need for any wrapping to propagate checked exceptions from the server to the client.

Hope this helps.
 
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that Remote method should throw RemoteException. That is what the question is how would you go ahead and implement this interface without breaking the contract.....

-H
 
Romeo Son
Ranch Hand
Posts: 92
Android Eclipse IDE Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used the Facade pattern to implement the network functionality
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harjit,

If you wish to wrap your exception in a RemoteException as described above do something like :
 
reply
    Bookmark Topic Watch Topic
  • New Topic