Contenu connexe Similaire à Sync is hard: building offline-first Android apps from the ground up (20) Sync is hard: building offline-first Android apps from the ground up 8. ©2014
Couchbase
Inc.
Saving
a
document
8
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("type", "list");
properties.put("title", title);
properties.put("created_at", currentTimeString);
properties.put("owner", "profile:" + userId);
properties.put("members", new ArrayList<String>());
// save to database
Document document = database.createDocument();
document.putProperties(properties);
@jamiltz
9. ©2014
Couchbase
Inc.
Saving
a
document
9
Document document = database.getDocument(myDocId);
String title = document.getProperty("title");
Map<String, Object> properties = doc.getProperties();
String owner = (String) properties.get("owner");
@jamiltz
10. ©2014
Couchbase
Inc.
Saving
a
document
10
Document document = database.getDocument(myDocId);
String title = document.getProperty("title");
Map<String, Object> properties = doc.getProperties();
String owner = (String) properties.get("owner");
@jamiltz
13. ©2014
Couchbase
Inc.
It’s
JSON
{
"_id": "123",
"type": "list",
"title": "TodoMVC list",
"owner": "1234567890",
"members": [
"0987654321",
"0192837465"
]
}
13
@jamiltz
19. ©2014
Couchbase
Inc.
Push
19
facebookAuthenticator = AuthenticatorFactory.createFacebookAuthenticator(accessToken);
Replication push = database.createPushReplication(SYNC_URL);
push.setAuthenticator(facebookAuthenticator);
push.setContinuous(true);
push.start();
20. ©2014
Couchbase
Inc.
If
you
were
to
build
your
own
▪ Create
a
job
object
that
has
an
action
▪ Write
data
to
a
durable
queue
▪ Run
a
service
to
process
the
queue
▪ The
service
retries
if
the
network
hiccups
or
app
crashes
▪ Remove
from
the
queue
once
the
job
is
complete
20
@jamiltz
27. ©2014
Couchbase
Inc.
Pull
27
facebookAuthenticator = AuthenticatorFactory.createFacebookAuthenticator(accessToken);
Replication pull = database.createPullReplication(SYNC_URL);
pull.setAuthenticator(facebookAuthenticator);
pull.setContinuous(true);
pull.start();
30. ©2014
Couchbase
Inc.
Pull
30
facebookAuthenticator = AuthenticatorFactory.createFacebookAuthenticator(accessToken);
Replication pull = database.createPullReplication(SYNC_URL);
pull.setAuthenticator(facebookAuthenticator);
pull.setContinuous(true);
pull.start();
32. ©2014
Couchbase
Inc.
Data
Flow
Techniques
32
Sync
Gateway
changes
feed
Push
notifications
worker
Continuous
push
@jamiltz
33. ©2014
Couchbase
Inc.
Data
Flow
Techniques
33
Sync
Gateway
changes
feed
Push
notifications
worker
Continuous
push
GCM
notification
GCM
notification
@jamiltz
34. ©2014
Couchbase
Inc.
Data
Flow
Techniques
34
Sync
Gateway
changes
feed
Push
notifications
worker
Continuous
push
One
shot
pull
One
shot
pull
@jamiltz
47. ©2014
Couchbase
Inc.
More
Information
47
James
Nocentini
Developer
Advocate
@jamiltz
ToDoLite
Android
https://github.com/couchbaselabs/ToDoLite-‐Android
Couchbase
Developer
Forums
http://forums.couchbase.com