| Author |
Question about exportObject
|
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
I have DataInterface. And the Data just implement this Interface. The RemoteData extends the Data and implements the the Remote. If I export the RemoteData from the Server site I can not cast the RemoteData to DataInterface. I know I did something wrong, but I need your advice me what is wrong? Regards, Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff, Your DataInterface will have to extend Remote and all remotely callable methods will have to throw RemoteException. Remote is a "tagging" interface like Serializable, having no methods of its own. It's only purpose is to let the RMI runtime (and rmic) know what methods to export on a remote object. Hope this helps, Michael Morris
|
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
|
 |
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
Thanks Michael Now the problem is that how to do the exportObject. Since this method only takes the the Object directly imlement Remoste. Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff,
Now the problem is that how to do the exportObject. Since this method only takes the the Object directly imlement Remoste.
Why do you need to call exportObject? All you should need to do is bind the object to the registry or return a Remote object from another bound Remote object and the RMI runtime will take care of exporting the objects. Hope this helps, Michael Morris
|
 |
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
Hi Michael The reason I export the RemoteObject is that My RemoteData extends Data instead extends UnicastRemoteObject. Thanks Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff, Sorry, I didn't catch that in your first post. I have to admit some degree of ignorance on the use of exportObject but it seems to me that you could just call UnicastRemoteObject.exportObject(remoteData, port) and then on the client typecast the exported object to a DataInterface. It's worth a shot to see if it works. Hope this helps, Michael Morris [ September 09, 2002: Message edited by: Michael Morris ]
|
 |
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
Thanks Michael This backs to my first post, when I try to cast RemoteData to DataInterface, I keep getting error like "java.lang.ClassCastException: suncertify.server.RemoteData_Stub" Thanks Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff, Does DataInterface extend Remote? Michael Morris
|
 |
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
Tahnks Michael, You are right. This is my problem. But my RemoteData now extends the Data, which implement DataInterface,the DataInterface extends the Remote, and the RemoteData implements the Remote again in order to do ExportObject. Is this ok? Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff, If RemoteData extends Data which implements DataInterface which extends Remote (whew! I'm glad I didn't have to say that) then RemoteData is already a Remote object and should not need to exlicitly implement Remote, although it shouldn't hurt anything either. Michael Morris
|
 |
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
Hi Michael This is exactly the problem. If the RemoteData dose not implement the Remote directly I can successful compile it, However when I do rmic RemoteData, it complains the RemoteData dose not implements Remote directly can not be exported. I start thinking changing my design instead extends Data may be just extends UnicastRemoteObject. Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff, It may be better not to have your remote object extend Data anyway. Just let it hold a reference to it instead and have it implement DataInterface directly and as you say extend UnicastRemoteObject. There is really no need for Data to implement DataInterface anyway, unless you are using Data directly in local mode. Michael Morris
|
 |
Jeff Shen
Ranch Hand
Joined: Sep 04, 2002
Posts: 31
|
|
Thanks Michael. I think I better let you advice me regarding the general design. DataInterface: define all the public method also extends Remote. Data: Implement DataInterface include criteriaFind. But the lock/unlock are empty. This class deals with local database. RemotData: extends UnicastRemoteObject and implements DataInterface. This class has also implement lock/unlock via LockManager. From client point view there is only one DataInterface. After the DataInterface reference to an Object depends on which one the client specified all behaviours regarding database are the same. Regards, Jeff
|
 |
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
|
|
Hi Jeff,
Data: Implement DataInterface include criteriaFind. But the lock/unlock are empty. This class deals with local database.
That broad design is identical to mine except for the above. I had a separate object that implemented criteriaFind and Data did not implement DataInterface (mine was called DataAccess), but your way is OK too. Michael Morris
|
 |
Mag Hoehme
Ranch Hand
Joined: Apr 07, 2002
Posts: 194
|
|
Hi, I've also had a problem with exporting or not exporting. After some research I found that there are two implementation strategies: 1. - you extend UnicastRemoteObject, and UnicastRemoteObject does all the exporting for you. 2. - you do some explicit exporting by calling by yourself: That's all the main thing about explict exporting. When you are extending UnicastRemoteObject, it is exactly this what happens in the UnicastRemoteObject's constructor. [ September 10, 2002: Message edited by: Mag Hoehme ]
|
Mag
|
 |
 |
|
|
subject: Question about exportObject
|
|
|