HI I implemented my server using RMI. The instruction says that server should be able to serve multiple client, so you need to make your server multi threaded. However with RMI even a single instance of DataClient is able to serve multiple Users. So is it still necessary to make the server multi threaded? I tried deploying DataServer as multi-threaded where every connection to dataserver will first get copy of DataClient, then this copy of dataClient will serve user's request. However I have to transport the entire DataClient to the user, which does not serve the purpose of RMI (wherein only stub is transported, and not the whole object). I think I am doing something horrible wrong, I just can't think of a good design to implement multi-threaded server in RMI. Any help in this respect will be greatly appreciated
Jignesh, Your RMI server should expose the same methods as the Data class. The server holds a single instance of the Data object and delegates calls down to the Data instance. Your stub is for the RMI server which is sent to the clients, the Data class stays put and must be thread safe. Only one server object gets registered. All clients issue a lookup and get a reference to the same RMI server instance. I created an interface which my Data class implements. Then I made a DataFactory class which returns the interface type. Have the RMI Server implement the same interface. Now the factory can return either an instance of a local Data class or the remote class. Your code references the interface and doesn't know the difference. The factory must determine which type to create based on the aguments passed (i.e., file, host, port).
It's a tiny ad. At least, that's what she said.
Devious Experiments for a Truly Passive Greenhouse!