• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RemoteException

 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,

I have a problem with RMI. I'm doing B&S. I have used the Denny's DVD example from the Monkhouse book and have come up with the following code:



Of couse DBMain is the interface that they provide us with and the class is the concrete version of this.

Now I have also a class that is defined thus:



Now in my RMI registry I place a object of type . However , there is a problem. If I make all the overridden methods in B (they override the methods in DBMain) throw RemoteException then I get compiler errors to the effect that the methods in B cannot override the methods in DBMain because the methods in DBMain do not throw RemoteExceptions. If then I take out the "throws RemoteException" statments from the method signatures of the methods in B I get the following runtime error:



From my limited understanding of RMI what this means is that the class that you put into the RMI registry must throw a RemoteException and since DBMain doesn't we have a problem. Does anyone know what the solution to this is?

Many thanks

Mandy
[ June 22, 2007: Message edited by: Barry Gaunt ]
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mandy,

If you search for RemoteException or Adapter Pattern, you will find a lot of posts reagarding approaches for handling the RemoteExceptions.

I think most people have used the Adapter Pattern to solve this problem

Adapter Patternn Example

Regards
Jason
 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having carefully read the linked post in its entirety I still don't understand how the adapter pattern is supposed to work. Also, no information is given about how exactly to use the Facade pattern. Any clarifications would be appreciated.

M
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mandy Bowman:
Having carefully read the linked post in its entirety I still don't understand how the adapter pattern is supposed to work. Also, no information is given about how exactly to use the Facade pattern. Any clarifications would be appreciated.

M


Here is a nice article from javaworld on the adapter pattern with RMI.

Adapter pattern with RMI

And an equally good one on the Facade pattern:
Facade Pattern
 
Mark Ebeling
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mandy,
Are you still having this problem? I am now having the same problem, even after reading the posted links. I am going down the same path I think you did using Andrew's book. The DVD sampleproject implementation class does not get the "overridden method does not throw RemoteException" when I build the sampleproject.

I followed his model and I get the above error when I compile for my Contractor Implemtation, saying that DBAccess does not use the RemoteException in the methods.

But I removed DBAccess from my remote interface and all is well. But I am concerned this not correct. Even though I implement the same methods as my Data interface. I think this is still an Adaptor pattern even though my remote interface and classes don't implement my Data interface.

Any commments or thoughts would be very helpful.

Thanks in advance.
 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mandy,
I think that there is no way to avoid placing an object of type B that implements Remote in RmiRegistry. The whole point is that your client must not deal with RemoteExceptions in its code, because it must be transparent for the client if the datbase is local or remote . Here helps the Adapter pattern.
You create a class DBAdapter that implements DBMain and receives a B object in the constructor for example. Then it implements the methods of the DBMain interface delegating to the the B class. The problem is here handling of RemoteExceptions that must obey the DBMain contract. There were some discussion regarding this matter on this forum also. There are solutions like setting the RemoteExceptions as cause of RecordNotFoundException or simply logging the exception and returning the null where is possible..
This is my understanding of the problem, I hope that helps...
Best regards,
Liviu
[ August 01, 2007: Message edited by: Liviu Carausu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic