用于传播对嵌套对象的更改的模式

用于传播对嵌套对象的更改的模式

本文介绍了用于传播对嵌套对象的更改的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施一个游戏/应用程序,将玩家的帐户/状态同步到服务器。我正在考虑一个通用框架,该框架传达一个实体(该实体是用户的帐户)的嵌套对象的修改。对于计算/反射的讨论,让我们假设客户端和服务器都是用Java编写的(实际上客户端是可以动态修改属性的ActionScript)

I am implementing a game/application where the player's account/state is synced to the server. I am contemplating a general framework communicating modifications of nested objects of an entity (the entity being the users's account). Let us assume for discussions of computation/reflection that both the client and server are written in Java (in reality client is in Actionscript which can modify properties dynamically)

。对根对象(Firebase对象)的任何对象的修改都会随请求传播,该请求可能类似于:

Take for instance Firebase. Modifications to any object of the root object (a Firebase object) are propagated with a request that probably looks something like:

Service: PersistenceService
Action: modifiedObjects
Body:
Objects [{"/full/Path/To/Object/1","newValue"},{"/full/Path/to/Object/2","newValue"}]

我的输入要求如下:

1)请更正和/或增强以下想法,以实现用于传播对对象树的修改的通用框架。

1) Please correct and/or augment the following thoughts on implementing this general framework for propagating modifications to a tree of objects.

在发送方,似乎每个对象都可以:

On the sending side, it would appear that every object either:

1)需要存储完整的对象根实体的路径

1) Needs to store it's full path from the root entity

2)对所有嵌套对象的属性更改都必须以反射方式完成

2) Changes to properties of all nested objects need to be done reflectively

OR

需要强制进行同步,将实体的已保存对象树(从上次请求到当前对象树)进行比较,以进行修改。

A sync needs to forced, comparing the entity's saved object tree from the last request to the current object tree for modifications.

在服务器端,可以分析对象的路径以缓存在一个请求中多次访问的对象,从而避免多次通过引用/搜索集合访问树。

On the server side, one can analyze the paths of the objects to cache objects that are accessed multiple times in one request so as not to access the tree by reference/search collections multiple times.

推荐答案

我想出的答案实际上非常明显,显然是最好的方法。答案是镜像表数据库。为每个对象分配一个ID,并将每个对象存储在ArrayList中(或为每个对象分配基于类型的唯一ID,然后将该对象存储在其类型的ArrayList中,该ArrayList本身存储在HashMap中)。

The answer I have come up with is actually very obvious the obviously the best way to do it. The answer is to mirror a database of tables. Assign each object an id, and store every object in an ArrayList (or assign each object a unique ID based on type and store the object in its type's ArrayList which is itself stored in a HashMap).

我称我的接口为ServiceObject和ServiceContainer。

I call my interfaces ServiceObject and ServiceContainer.

现在,我唯一能看到的就是json和proststuff如何序列化对对象的双重引用。它们被序列化为单独的对象吗?如果是这样,那么我需要对任何嵌套的ServiceObject进行反序列化,以引用ArrayList中的对象。

Now the only thing I have to see that works is how json and protostuff serialize dual references to objects. Are they serialized as seperate objects? If so, than I any nested ServiceObject's need to deserialized as references to the objects in the ArrayList.

这篇关于用于传播对嵌套对象的更改的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:50