I implemented the factory pattern as these: 1. The FactoryImpl is registered with the rmiregistry 2. The client requests a reference to a Factory 3. The rmiregistry returns a remote reference to a FactoryImpl 4. The client invokes a remote method on the FactoryImpl to obtain a remote reference to a ProductImpl 5. The FactoryImpl returns a remote reference to an existing ProductImpl. 6. The client invokes a remote method on the ProductImpl to run a testing object's method on the server side. Note: the FactoryImpl and the ProductImpl are remote objects. My enviroment is : Windows2000, single PC, use file url, server and client run in two seperated DOS_like windows. But above cann' work. If I modify the ProductImpl and the test object to implements Serializable, then it work! But the ProductImpl just works on client side instead of server side! I know the reason: the copy instead of remote reference of the two object be passed ! Problems are: 1. Must ProductImpl extend UnicastRemoteObject like FactoryImpl does? 2. Myst ProductImpl implements Serializable? 3. How should I modify it to make it work correctly? Could you help me?
Originally posted by HiBob Chu: [QB] Problems are: 1. Must ProductImpl extend UnicastRemoteObject like FactoryImpl does? 2. Myst ProductImpl implements Serializable? 3. How should I modify it to make it work correctly? [QB]
1. Given the framework you're using, yes and no. ProductImpl must be exported but could use the static method UnicastRemoteObject.exportObject() instead of extending the class. 2. If it's a parameter, yes. If it's its own exported thing, then no. 3. Use Jini to do this instead. You'll save yourself a lot of hassles.
subject: Problems about using Factory pattern to implement RMI