0

I have a certain problem: I'm using RMI to communicate between server and client.

public class RemoteMap
    extends java.rmi.server.UnicastRemoteObject
    implements RemoteMapInterface {

 private TreeMap<String, GeneralSprite> sprites;
...

This is my remote object. But I want the client to be able to change this object's content. And after the change the server can execute some operation based on this.

Example at the client side:

map = (RemoteMapInterface) (registry.lookup("map"));
map.getSprites.get("object1").setDx(-1);

I'm using serialiable on the GeneralSprite, but I guess it passed by value. So when I did some changes at the GeneralSprite, it wasn't transported to the server . Do I have to make GeneralSprite to an Remote object too? Or is it even possibly?

Thanks in advance, and sorry for my bad english, I hope you can understand.

Aksirba
  • 111
  • 1
  • 10

1 Answers1

0

Everything which does not implement the Remote interface, whether directly or indirectly, will get serialized for the remote method invocation. So it’s a “call-by-copy” behavior. You can implement a new Map which implements Remote, but you can also add a method like setDx(String spriteName, int value) to your RemoteMapInterface and implement it as sprites.get(spriteName) .setDx(value); on the server side.

Holger
  • 285,553
  • 42
  • 434
  • 765
  • Thanks, finally I could solve the problem with your help. But in the end, I think I wont use RMI. I'm developing a game, so I need to update real-time my server. And it looks like RMI isn't the best solution for it. Anyway thanks for the answer :) – Aksirba Oct 25 '13 at 19:07
  • Everything which either does not implement Remote *or which is not currently exported* will be serialized. – user207421 Oct 25 '13 at 21:32