• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI design

 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have downloaded the programming assignment. On the RMI, I have a question.
As you all might know there is a class provided with all the database access methods..like find,modify etc. We would need a server class that would extend unicastremoteobject and which would implement the interface(which would have all the exportable methods). Now, there are two ways of going about it.
FIRST WAY:
I can extend the class that they have given to me and have all the methods in there, throw a RemoteException
Second Way:
I can make my own class extend unicastremoteobject and then provide an instance of the class provided to me by Sun(which has all my DB access methods) in my class.
just to give you a better idea of the SECOND WAY, it looks like this
public class Myclass extends UnicastRemoteObject
implements myInterface
{
Myclass() throws RemoteException
{
super();
}
/*reference the method in the Data class*/
/*provided by SUN*/
public void find(String criteria)
{
new class Data("db").find(criteria);
}
....
...
public static void main(.....)
{
security stuff.............
Naming.rebind(......);
}
}

Is the SECOND WAY any good. Or is there a even better way?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Pkm"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
Stephane Weber
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's indeed the best way to do it in my own opinion.
Avoid however to use

new class Data("db")

in each method (find, add, modify, ...) and prefer to instantiate a Data object in the constructor of your Remote object, that you will keep during his lifetime.
Also, don't forget ot include in your interface definition the

throws RemoteException

for each method you specify.
Hope that helps
Stephane
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan:
I wasn't clear about your reply. Did u mean the second way is better or did u mean the first way is better
 
Allen Chan
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi St�phane,
Did you mean he has to throws the exception for each method like find, modify, delete?
Thanks,
Allen
 
Stephane Weber
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Prakash : I meant the second way.
Allen : Yes, if you want your RemoteData class (or whatever you called it) to be accessible remotely, you certainly made it implement the Remote interface. (Either directly, or by creating an interface of yours that does so, like RemoteDataInterface, specifying each add, find, modify, ... method with the additional throws RemoteExcpetion). Then this requires that each method you define at least throw RemoteException. (PLus of course the exceptions you would have to catch within your code).
Hope this helps
Stephane
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic