Java RMI:Updating client side objects in the server

社会主义新天地 提交于 2019-12-02 03:27:09
prmottajr

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 objectis 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 would have to 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

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!