wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Factory implementation fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Factory implementation fails" Watch "RMI Factory implementation fails" New topic
Author

RMI Factory implementation fails

Amy Young
Greenhorn

Joined: Oct 04, 2007
Posts: 7
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

Joined: Oct 04, 2007
Posts: 7
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

Joined: Feb 01, 2007
Posts: 77
How are you handling this object on the GUIController Side. how does your code look on that side ?

Thanks

- Harjit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Factory implementation fails
 
Similar Threads
[B&S] RMI client disconnect
is this 3-tier?
client locking for URlyBird 1.3.2
Stand alone criteria [B&S]
FBN RMI Design Question