Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI help needed  RSS feed

 
Richard Berg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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




  • Good Luck,

    Avi.


 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!