Java RMI:Updating client side objects in the server

后端 未结 2 1240
再見小時候
再見小時候 2020-12-12 05:02

I\'m trying to implement a middle-ware for group communication in a distributed system using Java RMI.

In there, I need to send an object to the server and modify it

相关标签:
2条回答
  • 2020-12-12 05:37

    When you use RMI you are having 2 (or more) java virtual machines involved in a given computation, so when you create an object at the client-side and call a method on the server passing this object as an argument the state of the object is serialized and sent through the network. On the server-side, a new object of the same class is created and the state is set on it, but it is a different object with the same values in it. Operating on this clone won't reflect on the original object that is still residing on the source virtual machine.

    You could use a rmiregistry on each machine that runs a virtual machine and registering each object to expose it (this is a distributed solution) or you could concentrate all the data objects on the machine that has the rmiregistry (this is a centralized solution, since all objects are on the same machine).

    Cheers!

    0 讨论(0)
  • 2020-12-12 05:38

    RMI isn't magic. It is Remote Method Invocation. You have to call a remote method to get something to happen in a remote place. Just changing a variable and having it magically propagate across a network isn't within the scope of RMI.

    Whatever you want to happen remotely has to be defined by methods in your remote interface(s).

    0 讨论(0)
提交回复
热议问题