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

NX: RMI Question from Max Book

 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble understanding something from Max's book in the RMI chapter, p. 171. He has the following:
1. DBClient interface similar to my DBAccess interface provided by Sun
2. DVDDatabaseRemote interface which simply extends Remote, DBClient, with no methods defined in it.
3. DVDDatabaseImpl which extends UnicastRemoteObject and implements DVDDatabaseRemote.
4. DVDDbAdapter which implements DBClient
His DVDDatabaseImpl methods throw RemoteException. From what I understand, this is allowable because DVDDatabaseImpl implements the DVDDatabaseRemote interface which extends the Remote marker interface.
His DBClient methods, like my DBAccess methods, do NOT throw RemoteException.
His stuff compiles successfully for me and works great. However, I have an extremely similar situation and I get a compile error:
MyImpl.java:???: readRecord(long) in MyImpl cannot implement readRecord(long) in DBAccess; overridden method does not throw java.rmi.RemoteException
This error makes sense, because the readRecord(long) in my DBAccess does not throw RemoteException. But what I'm trying to figure out is why it works in his situation, since his DBClient also does not throw RemoteException
Thoughts???
TJ
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TJ,
It took me a little while to figure this out when I was studying this code for my own assignment.
RemoteException is an IOException. Note that all of Max's DBClient methods throw IOException. I used the same technique in my code. It's a nice little RMI trick that makes things easy if all the methods in the interface are IO oriented.
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ken. That was driving me crazy. I knew Max had an IOException, but I didn't realize that RemoteException was one.
Thanks for not saying "read the API, dummy".
TJ
 
amchi gelo
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Krebs:

RemoteException is an IOException. Note that all of Max's DBClient methods throw IOException. I used the same technique in my code. It's a nice little RMI trick that makes things easy if all the methods in the interface are IO oriented.

But then we are forbidden from tinkering with DBAccess interface right? Then how did you make this change?
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sanjay,
Originally posted by Sanjay Joshi:

But then we are forbidden from tinkering with DBAccess interface right? Then how did you make this change?

I'm not speaking for Ken as to how he did this, but one way is simply to have another interface and use the adapter design pattern to adapt this new interface to the Sun-supplied one. Then you basically just use your new interface in place of the Sun-supplied one. You still implement the Sun-supplied interface in Data, but for all other purposes you use your new interface. Of course, Data must implement your new interface (but not necessarily explicitly).
Hope this helps,
George
[ January 25, 2004: Message edited by: George Marinkovich ]
 
amchi gelo
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hurrraaaayyyyyyyy!!!
I finally got the RMI part to work, thanks to you George, for the tip!
Next time the beer is on me!
For the others who are where I am, here's a nice tutorial on the Adapter Design Pattern which works like a charm.
http://www.javaworld.com/javaworld/jw-05-1999/jw-05-networked_p.html
Sanjay
Originally posted by George Marinkovich:
Hi Sanjay,

I'm not speaking for Ken as to how he did this, but one way is simply to have another interface and use the adpater design pattern to adapt this new interface to the Sun-supplied one. Then you basically just use your new interface in place of the Sun-supplied one. You still imlement the Sun-supplied interface in Data, but for all other purposes you use your new interface. Of course, Data must implement your new interface (but not necessarily explicitly).
Hope this helps,
George
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic