保持远程对象更新
具有同一类(例如 HashMap)的两个对象A、B。
在通过互联网连接的不同计算机上,
一台(A)是源,另一台(B)只是更新的副本...
是否有标准/保持它们“连接”或“更新”的推荐方法?
示例
我正在使用 TCP 连接和 writeObject
ObjectOutputStream bufferObj = new ObjectOutputStream(out);
bufferObj.writeObject(A)
并在复制端类似这样
ObjectInputStream bufferObj = new ObjectInputStream(in);
对象B = bufferObj.readObject();
但这有一个问题,即每次同步时都会发送整个对象 (例如定期或每次发生修改时)
我想要一种仅发送差异的方式(对于 Java 集合特别有用),但了解差异并不是一件容易的事情,至少
我想 有这样的东西(过于简单/乐观的方案)
在服务器源
ObjectA.serverUpdatesWarehouseAt(端口);
在客户端复制
ObjectTemp.updateItRemotelyFrom(IP,端口);
ObjectB.merge(ObjectTemp); //根据需要更新差异添加/删除
已经做了这样的事情吗?所以我在这里,试图避免重新发明轮子,
感谢您的阅读
Having two object A, B, of the same Class (for example HashMaps).
At different computers connected by internet
One (A) is the source and the other (B) is just as an updated copy...
Is there a standard/recommended way to keep them "connected" or "updated"?
Example
I am using a TCP connection and writeObject
ObjectOutputStream bufferObj = new ObjectOutputStream (out);
bufferObj.writeObject(A)
and in the copy side something like this
ObjectInputStream bufferObj = new ObjectInputStream(in);
Object B = bufferObj.readObject();
But this have the problem that the whole object is sent in every synchronization
(for example periodically or everytime a modification occur)
I would like a way of sending only the differences (specially useful for Java collections), but knowing the difference is not an easy thing at least
I would like to have something like this (overly simple/optimistic scheme)
At the server source
ObjectA.serverUpdatesWarehouseAt(Port);
At the client copy
ObjectTemp.updateItRemotelyFrom(IP,Port);
ObjectB.merge(ObjectTemp); //update the differences adding/deleting as needed
Is anything like this already made ? so here I am, trying to avoid reinvent the wheel
thanks for reading
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您可能会受益于分布式哈希映射( http://en.wikipedia.org/wiki/Distributed_hash_table )。
有不少框架提供此类功能 - http://code.google.com/p/hazelcast / 就是一个例子。
冒着陈述显而易见的风险 - 如果您的更新率很高,您可能会占用大量带宽来保持两者同步。
It sounds like you might benefit from a Distributed Hash Map ( http://en.wikipedia.org/wiki/Distributed_hash_table ).
There are quite a few frameworks which provide such functionality - http://code.google.com/p/hazelcast/ is one example.
At the risk of stating the obvious - if your update rate is high you can use up a lot of bandwidth keeping the two in sync.
如果您使用 RMI,您可以拥有分布式对象,因此您根本不必担心保持它们更新。一旦您引用了该对象(在客户端上),它就会自动与服务器的对象保持同步。
If you use RMI you can have a distributed object, so you don't have to worry about keeping them updated at all. Once you have a reference to the object (on the client) it is automagically kept in sync with the server's object.
你可以看看 Terracotta ,它正是做这种事情的。它们允许在 JVM 之间创建保持同步的共享对象。
You could have a look at Terracotta which does exactly this kind of thing. They allow creation of shared objects between JVM which are kept synchronized.