8. Sync engine with event hub noti cations in repository
1. ARCHITECTURE EVOLUTION
9. Can contain a memory cache
Plain object
Easy to handle
Easy to inject
Easy to test
Hard threading
Dependent from other layer
Service
Easy to handle
Hard to inject
Hard to test
Easy threading
Independent from other
layer
2. ARCHITECTURE ELEMENTS: REPOSITORY
10. The only source of truth
Plain object
Easy to handle
Easy to inject
Easy to test
Hard threading
Dependent from other layer
Content provider
Hard to handle
Hard to inject
Hard to test
Easy threading
Independent from other
layer
2. ARCHITECTURE ELEMENTS: DATABASE REPOSITORY
11. With reference to the network client
Plain object
Easy to handle
Easy to inject
Easy to test
Hard threading
Dependent from other layer
2. ARCHITECTURE ELEMENTS: NETWORK REPOSITORY
12. Make it from Android
Plain object
Easy to handle
Easy to inject
Easy to test
Hard threading
Dependent from
other layer
Service
Hard to handle
Hard to inject
Hard to test
Easy threading
Independent
from other layer
Make it intelligent
Sync adapter
Job scheduler (or
similar)
2. ARCHITECTURE ELEMENTS: SYNC ENGINE
16. The backend have to be prepared to make the sync more smooth
{
"syncTimestamp": 1467361858958,
"created": [
{
"name": "Instance 1057",
"module": "571f38b9bb7f372900a14cbc",
"createdAt": 1464000087974,
"updatedAt": null,
"deletedAt": null,
"id": "5742de576ec1322f00d796c5"
}
],
"updated": [],
"deleted": []
}
Not json patch, just timestamp!
3. WEB SERVICES AND PERFORMANCE: BACKEND
17. How to dispatch in Backend
Without timestamp cache
With timestamp bring only the changes
Prepare to receive a bunch of very small requests
3. WEB SERVICES AND PERFORMANCE: BACKEND
18. How to request in Android
First request send without timestamp and with cache ag
Inmediatly make a request with the timestamp from server to
now
Request every 'n' time or when the user needs to (internet
connection handing)
Use a cursor to display it and not ll your memory
3. WEB SERVICES AND PERFORMANCE: FRONTEND
19. Depending on the device, database used and network
Fetch, save and display takes...
3. WEB SERVICES AND PERFORMANCE: TIMING
1500 INSTANCES / SEC
21. Handle all your threading in the same class
If you are not a hipster that uses RxJava
4. THREAD MANAGER
22. 39. case SAME_THREAD_POLICY:
40. future = new FutureTask<>(runnable,
null);
41. runnable.run();
42. break;
32. switch (thread) {
33. case POOL_QUEUE_POLICY:
34. future = mPoolQueue.submit(runnable);
35. break;
36. case SINGLE_QUEUE_POLICY:
37. future =
mSingleQueue.submit(runnable);
38. break;
43. default:
44. throw new
HaloConfigurationException("Unsupported option or
an Action operation");
45. }
46. return future;
47. }
48. }
23. JobScheduler jobScheduler = (JobScheduler) getApplicationContext().getSystemService(JOB_SCHEDULER_SERVICE);
ComponentName componentName = new ComponentName(getApplicationContext(), TestService.class);
JobInfo jobInfo = new JobInfo.Builder(1, componentName)
.setOverrideDeadline(10)
.setRequiresCharging(true)
.build();
jobScheduler.schedule(jobInfo);
Only for 5.0+!!!
5. JOB SCHEDULER AND FAMILY
24. You can use GCMNetworkManager from google
or Trigger
5. JOB SCHEDULER AND FAMILY
25. Trigger sample
Job job = new Job(new Action() {
@Override
protected void act() {
//do something
}
}).withExtra(new Condition() {
@Override
public String[] getAction() {
return new String[]{YOUR_BROARCAST};
}
});
trigger.schedule(job);
5. JOB SCHEDULER AND FAMILY