• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI : local/remote with one class

 
jay mer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure I'm missing something obvious here, but why can't I simply use the same class (ie Data) for local and remote connections?
In other words something like this:
Data db = null;
if (remote){
db = (Data)Naming.lookup("RemoteData");
} else {
db = new Data();
}
This approach seems to fit the requirement, but it's so easy that I'm thinking something must be terribly wrong with it...
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure I'm missing something obvious here, but why can't I simply use the same class (ie Data) for local and remote connections?
In other words something like this:
Data db = null;
if (remote){
db = (Data)Naming.lookup("RemoteData");
} else {
db = new Data();
}
1. What are you doing with Data? Is Data a remote object? How are you going to access it?
2. How will you enforce that the DataClient should implement all methods of the Data object. Tomorrow, if I add a new method to Data, what will ensure any developer that the api is the same?
Think about it
 
jay mer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I guess I didn't give enough information...
Yes, I have made Data a remote object. I've extended UnicastRemoteObect. I have also created an interface that has the same public methods as Data and extends Remote and I have implemented that interface in Data. So my code actually looks a little more like this:
DataInterface db = null;
if (remote){
db = (DataInterface)Naming.lookup("RemoteData");
} else {
db = new Data();
}
Essentially, what I am doing is using Data for both local and remote modes. The only difference is the way I obtain the reference and, as a result, which vm the object exists in...
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so you made Data a remote object? Let me ask you this, why does the Data class have to be remote when accessed in a local mode. It will work fine alright. However, is it aesthetic?
If you can justify your reason for making data directly a remote object, thats great. Remember, the statement,that we will not be penalized for an approach as long as we stay consistent with that approach and justify it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic