简体   繁体   English

同步机制,例如Java / Android中的Google云端硬盘

[英]Sync mechanism like Google Drive in Java/Android

I am trying to develop a mechanism for Sync data with app & server, like Google Drive/Dropbox for one of my android based application where data are stored locally on device and I would like to sync data with server. 我正在尝试开发一种与应用程序和服务器同步数据的机制,例如针对基于Android的应用程序之一的Google Drive / Dropbox,其中数据存储在设备本地,并且我想与服务器同步数据。

Ways thought - 思维方式-

1) Observer which looks for change and call web service 1)观察者,寻找改变并呼叫网络服务

2) Background service which runs in background and check for changes 2)在后台运行并检查更改的后台服务

3) Set Alarm which checks at particular time and sync all the data with server 3)设置在特定时间检查并与服务器同步所有数据的警报

I have not started to which option to go with, I would like to get experts view on this and like to get some guidance so that I can achieve the sync mechanism in best possible way for my app. 我还没有开始选择哪个选项,我想征求专家的意见,并希望获得一些指导,以便我可以为自己的应用以最佳方式实现同​​步机制。

All suggestion are welcome. 欢迎所有建议。

Thinking on same line as you have been,the aim should be to achieve a balance between the number of times the server is queried for same set of information AND the data consistency. 与以前一样,我们的目标应该是在查询服务器以获取相同信息集的次数与数据一致性之间取得平衡。

for this, I would fire a GCM message from my server to the device for which the data on the server has changed, I would maintain a count for these Update Messages(No Notification genereated). 为此,我会将GCM消息从服务器发送到服务器上数据已更改的设备,我将为这些更新消息计数(不生成通知)。 If this count Exceeds the minimum-threshold-count-value, I would immediately call for an UPDATE. 如果此计数超过最小阈值,我将立即要求进行UPDATE。 Or otherwise, if this count still is less than the threshold-count-value, for a certain period, that I would call the threshold-waiting-period, then too I call for an UPDATE. 否则,如果在某个时期内此计数仍小于阈值计数值,我将其称为阈值等待期,那么我也要求进行UPDATE。

The UPDATE would be using Sync Adapters and Services. 更新将使用同步适配器和服务。 This link explains its basics. 此链接说明了其基本知识。

Hope this prooves to be helpful! 希望对您有所帮助!

...so that I can achieve the sync mechanism in best possible way for my app

Well, the BEST mechanism depends completely on what kind of application, you are developing. 好的,BEST机制完全取决于您所开发的应用程序类型。 Also, your option 1 and 2 seems very similar to me except few implementation changes. 另外,您的选项1和2与我非常相似,只是实现上的更改很少。 However, how frequently your device data is changing, that also matters a lot. 但是,设备数据的更改频率也很重要。 If you have authentication mechanism, you can configure sync up, at the time, whenever you login to your app. 如果您具有身份验证机制,则可以在每次登录应用时配置同步。 Like in case of confidential data, sync up should happen immediately. 与机密数据一样,同步应该立即发生。

If data is managed well based on authentication and authorization based on user roles or so, you also need to take care of synchronization among them. 如果根据基于用户角色的身份验证和授权对数据进行了很好的管理,则还需要注意它们之间的同步。 For example, one user has updated an entity which is not yet sync and another user tries to update the same, then first user will see his changes are not synced or has been lost. 例如,一个用户更新了一个尚未同步的实体,而另一个用户尝试更新该实体,那么第一个用户将看到他的更改未同步或已丢失。

The best way (means having least drawbacks) to do this would be sync up trigger at a particular interval of time OR at every login time. 最好的方法(意味着缺点最少)是在特定时间间隔或每个登录时间同步触发。 (still as I said, depends on your app). (仍然如我所说,取决于您的应用程序)。

Hope this would clear some or all of your doubts. 希望这能消除您的部分或全部疑问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM