• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: RMI Factory Question

 
oli renard
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
oli renard
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic