• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI Factory implementation fails

 
Amy Young
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have chosen to implement RMI for my application.
In the suncertify.gui.GuiControlle I do the following:

case NETWORK_RMI:
remoteConnection = suncertify.remote.RmiClient.getRemote(
dbLocation, port);
break;

The suncertify.remote.RmiClient.getRemote is implemented as follows:

try {
DataRemoteFactory remoteFactory = (DataRemoteFactory) Naming.lookup(url);
DataRemote remote = remoteFactory.getClient();
DataRemoteAdapter res = (DataRemoteAdapter) remote;
return res;
}

The loookup goes well , at least I see, debugging, that an object is received.
The DataRemoteFactory also returns an object which when printed out looks like this:

Proxy[DataRemote,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoin
t:[127.0.0.2:1057](remote),objID:[440b37a7:1158b7f57c8:-8000, 1]]]]]

Indeed the DataRemoteFactory should instantiates (and returns) an object of type DataRemoteImpl which extends UnicastRemoteObject and has though composition a reference to the DataRemoteAdapter class.

The problem takes place when the remote object is casted to suncertify.db.DataRemoteAdapter which through composition has an instance of DBAccess dba = new Data(); and implements all the method given by the Sun inteface.

Since the casting is failing I'm wondering what kind of type the received "DataRemote remote" has at runtime .When usinf getClass(0 on it , I see the : "class $Proxy1"

Greetings

Amy
 
Amy Young
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo everybody

I found the solution!!!
The DataRemoteImpl must be of type : DBAccess!!!

This is the way I implemented it:

suncertify.db.DBAccess <-- given by SUN
suncertify.db.Data <-- implementation of DBAccess
suncertify.db.DataRemoteAdapter extends Remote <-- interface which declares all methods declared in the DBAccess. because this uses the Remote interface I'll be able to throw RemoteException as required by RMI.
suncertify.db.DataRemoteAdapterImpl implements DataRemoteAdapter <-- has a reference to the Data class and calls the Data's methods.

suncertify.remote.DataRemote extends Remote, DataRemoteAdapter
suncertify.remote.DataRemoteImpl extends UnicastRemoteObject implements DataRemote

And here it comes the RmiClient has a method called by the GUIController :

public static DataRemoteAdapter getRemote(String hostname, String port)
throws RemoteException {
String url = "rmi://" + hostname + ":" + port + "/DataRemote";
log.info("URL = " + url);
try {
DataRemoteFactory remoteFactory = (DataRemoteFactory) Naming.lookup(url);
}
DataRemote remote = remoteFactory.getClient();
DataRemoteAdapter dra = (DataRemoteAdapter) remote;
return dra;
}catch (){
//all kind of exceptions
}
}

I hope someone else will be helped by this...

Bye

Amy
 
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you handling this object on the GUIController Side. how does your code look on that side ?

Thanks

- Harjit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic