Hello everyone, I have made great progress so far, but I still fail to understand how to implement the Factory pattern in RMI. I have read many posts on this wonderful site (without which I would not even stand a chance of passing the assignment), but I do not understand how to implement the above. I have a ContractorServices interface, which is the main interface which acts a the connection interface. As a result, I have an implementation with the LocalContractorServicesImpl class for the "alone" mode and this works fine. On the server side, I have created a new interface, RemoteContractorServices, which implements both ContractorServices and Remote. My implementation of this interface, RemoteContractorServicesImpl implements the RemoteContractorServices interface and extends UnicastRemoteObject. It also contains an instance variable of the Data class which provides access to the database (read, update, find, etc.). Now, my understanding of the RMI Factory is that it would contain a createRemoteImpl method (or whatever one might want to call it) that would return a new instance of RemoteContractorServicesImpl every time it is invoked by a different client. However, from the RMI Factory examples that I have seen, the objects returned by the factory implement the Serializable interface, which would imply that the RemoteContractorServicesImpl would implement the Serializable interface and that Data would have to implement the Serializable interface as well and so on. However, this just does not seem right and given that other people have managed to use an RMI Factory, I am asking all talented people for their help in understanding this issue. I am probably completely misunderstanding this RMI Factory concept, but I would be very grateful if someone could help me understand it. Thank you very much indeed. Oli
Oli, As you have said, your Data object is an instance variable in your RemoteContractorServicesImpl. It will not get passed over the wire unless it is referred to as an argument in a method call or is returned as the result of a method call. Remember that your client factory method returns a proxy for you to use with which you can indirectly call methods on the RemoteContractorServicesImpl which will in turn, presumably, call methods on the Data instance which lives on the server side. Hope that clears it up.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
posted 16 years ago
Ken, thank you ever so much. It is clear now. I always assumed that the Data object has to be returned over the wirse, but obviously not. It is clear now, thank you. Oli
It will give me the powers of the gods. Not bad for a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop