Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top