This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Factory implementation fails" Watch "RMI Factory implementation fails" New topic

RMI Factory implementation fails

Amy Young

Joined: Oct 04, 2007
Posts: 7
I have chosen to implement RMI for my application.
In the suncertify.gui.GuiControlle I do the following:

remoteConnection = suncertify.remote.RmiClient.getRemote(
dbLocation, port);

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:[](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"


Amy Young

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";"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...


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 ?


- Harjit
I agree. Here's the link:
subject: RMI Factory implementation fails
It's not a secret anymore!