1

I want to know if it is possible to pass an object by reference with java RMI.

To be more specific I want to do something like this

Client end:

server.getSomeitem(someitemID).getSomeOtherItem(otherItemId).setItemValue(String someValue);

Where on the server end the getsomeitem object returns an object with the index that is sent in, then off of that object call getsomeotheritem from that index then call setItemValue on that object.

I want this to affect that values on the server side and not just sent a copy of the objects to the client.

Is this possible?

ntzm
  • 4,663
  • 2
  • 31
  • 35
awmusic12635
  • 1,241
  • 2
  • 11
  • 13
  • http://stackoverflow.com/questions/3087756/rmi-pass-by-value-or-by-reference – Santosh May 11 '14 at 20:55
  • I have tried that however I still seem to be getting issues – awmusic12635 May 11 '14 at 21:27
  • Getting the first item works fine however anything after that gets a null – awmusic12635 May 11 '14 at 22:01
  • Copying a comment from EJP here (I think it is correct): "RMI passes remote references by value, just like the JVM does with parameters. It passes non-remote parameters by value. By-reference doesn't come into it anywhere." (see comments on [this answer](http://stackoverflow.com/a/3087795/3080094) from the previously mentioned question) – vanOekel May 11 '14 at 23:41

1 Answers1

1

If the object concerned is an exported remote object its (remote) reference will be passed. Otherwise the entire object is passed by value copy via Serialization.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Does each object need to be exported separately?. Say the first one it gets is a different class than the second one it gets. I guess I am a bit confused about which objects need exported and how to do that. I have the first object where the first method is called exported and from that I am getting the others currently. – awmusic12635 May 12 '14 at 01:37
  • I suggest you just stop, calm down, and read my answer again. – user207421 May 12 '14 at 10:46