This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI in Java Developer

 
Tim Adam Cooper
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating an interface for Remote Method Invocation in which all the methods throws RemoteException.
However, there is a query: The Developer exam say that the user can used local or remote access.
Is that OK that both the local and remote used that interface in which all the method throw RemoteException or should the local used a different interface that does not throw RemoteException?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
Actually you can decide how you wish to proceed. You can use two interfaces. I had one interface that extended Remote but just threw Exception, so I could then throw any type I wanted to int he implementing classes. However, I am not sure that that is the best way.
Anyone else have suggestions?
Mark
 
Pete Lyons
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just had one interface that threw RemoteException in addition to any other exceptions, and documented the fact that these would never be thrown by a local implementation. I was not really happy with this design, but it was expedient, so I did it, and it seemed to be tolerated by the assesor.
 
HiBob Chu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
Yes, I use one interface too. Before , I couldn't sure whether it is fine or not. Now
I think it's no problem in logic. I think that
the class implements a remote interface means it
has the ability provided by the interface instead means it has to do every time. For example , you can create a class which implements Serializable , but you can use it without serialize it.
Wish this help you.
[ November 26, 2002: Message edited by: HiBob Chu ]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pete Lyons:
I just had one interface that threw RemoteException in addition to any other exceptions, and documented the fact that these would never be thrown by a local implementation. I was not really happy with this design [...]
Do be happy. This works exactly the way it should do.
The fact that the interface throws RemoteException is an expression of the fact that implementations of this interface may be Remote. Any code using this interface should not care about the particular implementation it's working with; client code simply needs to cater for the fact that RemoteException may be thrown and doesn't care about whether it can be thrown by the particular implementation or not.
You do not really need to document that RemoteException is never thrown in a local implementation. The code that is using the interface shouldn't even have to know that there is a local implementation in the first place. Any code that needs a local implementation to work correctly should use Data directly (or perhaps a LocalDataInterface which extends DataInterface and strips all the RemoteExceptions).
By the way, you could argue that the DataInterface methods should all throw IOException rather than RemoteException, to express the fact that socket-based implementations are valid as well as RMI-based ones.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic