• Post Reply Bookmark Topic Watch Topic
  • New Topic

Are RMI Server objects stateful?

 
Ninju Bohra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I retrieve a server object from one client and call a remote method (say incrementValue() ) and then from another client (or even the same client) I retrieve an object using the same URL string and call getValue(), will the object be same object and is that state maintained?
 
Carr Onstott
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yer question honestly does not necessarily pertain to RMI. RMI Server objects are "stateful" if they are implemented as such. If you lookup the same server from two different clients then they will both be making calls back to the same process that is running. So if you call incrementValue() from one and then getValue() from another, then assuming that the server actually does increment the value you think it does, then yes you will get the incremented value when you call getValue().

Here are a couple examples. The first is the remote interface definition. The first class then is a stateless server that doesnt do anything when incrementValue() is called and always returns 0 for getValue(). The next is one that actually keeps track of an int and increments it when incrementValue() is called and returns that value in getValue().

 
Ninju Bohra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx...

So, regardless of whether I implement my Server code to retain state or not, all client "lookup"s for the remote object will be handled by the same object instance? In fact, to answer my own question, the instance that will be handling the calls is the one that was given to the .rebind(...) call during server startup/registration. If I choose to implement state (as the incrementValue() and getValue() methods could be used) maintainence then the state would be kept.

That being said, I have one more closely related question... is there any from the server side to identify the client that invoking me (client IP address, PID, etc...) or is the server object unable to distinguish this?

Thanx again...
 
Carr Onstott
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no built in mechanism to determine the caller of a method. As a matter of fact, you can call remote methods from within the same class. If the caller matters then you should send a String name or some other identifier as a parameter to the method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!