Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

B&S General question on RMI

 
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
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • 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
 
    Bookmark Topic Watch Topic
  • New Topic