Hi all! Need some help with RMI: I have an RMI server and a handful of clients. I want a new instance of object X to be created on the server to serve each client. X will then access a database located on the server and send query results to the client. There MUST be one and only one instance of X for each client! I've succeeded in creating one instance of X to serve all clients, but I must have one for each (to keep track of the clients). My problem is that I don't know where to start! Would someone please post some short example code for rhis?
Create a "factory" class that creates and returns instances of X. Example:
<blockquote> <pre> public class XFactoryImpl extends UnicastRemoteObject implements XFactory { public static synchronized X createX() { return new XImpl(); } } </pre> </blockquote>
Remember...
Register class XFactoryImpl
Don't register XImpl
Client does a lookup of XFactory and then invokes createX
hi, every client can pass its id to server. create a session object with this id. this session has a field for X.if you create session object, then you also create X. before creating a new session object you check if one exists already (perhaps store them in a hashtable). if it exists then pass back existing one, if not create new one. in this way you only have one X per client. would this work for you ? karl
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad: