• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

RMI help needed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Those are the largest trousers in the world! Especially when next to this ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic