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

B&S General question on RMI

 
Surya De
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow ranchers,
My question to you today is regarding RMI. This is my first time using RMI. I understand overall the idea and how to go about implementing RMI. But overall knowledge is not enough to make you write RMI code. So here I am.

I have an interface...the Remote interface that will have the method stubs which represent the remote functions that the client will be able to call. So I am thinking that since for the assignment Sun has already assigned me with a DB class, the remote interface for RMI purposes will be remarkably similar to that of the DB class...is that a correct statement?

If so then can I do this and this will be the entire remote class:


So when I finish the implementation of the above methods and I start compiling me new classes for my remote package I hit a snafu. Because the methods in that interface need to be throwing a RemoteException I am getting errors during compile time.

So instead I said ok fair enough I wont extend the DB interface as above but I will just copy the methods and paste it in the Remote interface just to get things moving. I do that and everything is fine. But something tells me that is not the right way to go about it. This is after all an object oriented paradigm and thus I should be able to by all rights be able to just implement the DB interface and not worry about anything else.

I hope my problem makes sense. I am sure it is a very simple solution that I am overlooking out of sheer frustration.

Best regards,
Surya
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Surya,
I have an interface...the Remote interface that will have the method stubs which represent the remote functions that the client will be able to call. So I am thinking that since for the assignment Sun has already assigned me with a DB class, the remote interface for RMI purposes will be remarkably similar to that of the DB class...is that a correct statement?
That is a reasonable statment, and one that I personally agree with. However, in fairness, I should point out that many members also feel that they should only expose business logic from the server, so they define their own interface which has nothing to do with the DB class. For more discussion on exposing all your DB methods / only exposing business methods, I recommend you take a look at "Should lock methods be callable by the client".

If so then can I [have my remote interface extend DB? However] Because the methods in that interface need to be throwing a RemoteException I am getting errors during compile time.
I think you have answered your own question. Because DB does not throw RemoteException (or a parent of it) you cannot simply extend it that way. An adapter class will probably solve your problem.

(Side note: I suspect that Sun may have created this little problem to give RMI programmers something to do. Socket programmers dont have this sort of problem (but they have their own problems)).

So instead I said ok fair enough I wont extend the DB interface as above but I will just copy the methods and paste it in the Remote interface just to get things moving.
And throw the correct exceptions I hope.
I do that and everything is fine. But something tells me that is not the right way to go about it. This is after all an object oriented paradigm and thus I should be able to by all rights be able to just implement the DB interface and not worry about anything else.
See my earlier comment about my personal suspicions regarding this . But to answer your unspoken question: it is not that you are missing something - the interface provided is not designed for RMI. Some solutions are to have an Adapter, or only expose business methods (ignoring the problem altogether), or use sockets.

Best regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic