Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LocalData,RemoteData

 
J Hartley
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i know there are a number of similar threads, but i just dont get it!
Im using RMI. My calls to the Data class may be remote or local, i think i have to make these calls transparent of location.
So i need a toplevel interface with public methods throwing Exception...ok i did this.
Then i Have LocalDataInterace which extends my toplevel interace to throw DataBaseExceptions and IOexceptions instead of Exception. my LocalData class can now implement this.
Now the probelem is the remote version. what the hell do i do?
If i extend the toplevel interace to create a new interface that throws RemoteException..but stop, i need to also extend Remote!! ugrgh bugger!
Thanks For Help!
Joe
 
Matt Cannata
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have an interface (I called it Database) that extends Remote, defines all Database methods and throws RemoteException and in the appropriate cases DatabaseException. Then create a RemoteServer interface that extends that interface. Have your Data class implement the Database interface, and your RMI Server class implement the RemoteServer interface. On the client side, you can treat everything as type Database. This way, you don't even have to throw Exception.
Hope this helps,
Matt
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt,
It seems to me we do not need go through an interface for local access. In local access, I would just initiate a Data object locally that proceed from there.
Then the remote access will go through interface according to RMI protocol.
Please comments
Ruilin
 
Aleksey Matiychenko
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So all you need is another class (adaptor or proxy) that hides remote exceptions from client
 
olivier roussille
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only one interface: "RemoteData" and only one class "Data"
I put the same files on the client and on the server.
RemoteData extends Remote. The methods throw RemoteException, DatabaseException and IOException (not all of them).
Data extends UnicastRemoteObject implements RemoteData
In my program client, I have (roughly):
RemoteData data;
if (LocalMode) {
data = Data(path of the file Db.db);
} else {
data = bind(the server,the data);
}
You know what? It works.
Of course, in local mode, the methods are allowed to throw remoteException (because of the interface) but they never throw RemoteException. It is not a problem for me. Is it a problem for you?
Regards,
Olivier
 
J Hartley
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm I think I may try Oliviers Method, it looks pretty simple.
I was finding it difficult to understand this problem because I was incorrectly assuming that my localData class had to be pure!, and not involoved with any fancy RMI( my LocalData would be releated to my RemoteData class because of my Top Level Interface, but it would not know about RMI).
Does anyone think there is anything seriously wrong with Oliviers Method?(Dont take offense Olivier ).
Cheers Joe
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just define another class (different name or so) for the local access doing the same thing as Data class, except not extending Remote and not extending UnicastRemote.
It is very simple to implement.
Please comment on my approach
Thanks
Ruilin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic