The best difference between object lists in Java

I have a list of Java objects on my server, which is sent to the client through some serialization mechanisms Occasionally, the object list is updated on the server, that is, some objects are added, some are deleted, and others only change their position in the list I want to update the list on the client, but send as little data as possible In particular, I don't want to resend existing objects on the client

Is there a library that can make a difference between the two lists, so I can only send differences and new objects?

I found several Java implementations of UNIX diff command, but this algorithm is not practical for order change Namely [a, B, C] – > [C, a] can only be sent as location change [1 - > 3] [3 - > 1], and diff will resend the entire a and C objects (as far as I know)

Solution

I do this by silently modifying objects' public interfaces, keeping a log of changes, that is, adding an object representing each modification to the modification list

In this way, you can get the smallest list of exact changes sent to other computers without having to infer them by comparing the old and new versions with wrong guesses

To create an object model to automatically record changes to yourself, you may benefit from some code generation or AOP to avoid a large number of repetitive patterns Setting property values or adding / removing methods from the list requires calling the central log shared by the object hierarchy

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>