Skip to content

Instantly share code, notes, and snippets.

@tleyden
Last active December 24, 2015 22:59
Show Gist options
  • Save tleyden/6876753 to your computer and use it in GitHub Desktop.
Save tleyden/6876753 to your computer and use it in GitHub Desktop.
Kickoff replication
public void startReplicationsWithFacebookToken(String accessToken, String email) {
Log.d(TAG, "startReplicationsWithFacebookToken()");
httpClient = new CBLiteHttpClient(server);
dbInstance = new StdCouchDbInstance(httpClient);
// create a local database
couchDbConnector = dbInstance.createConnector(DATABASE_NAME, true);
startReplicationsWithUrl(getReplicationURL().toExternalForm());
}
public void startReplicationsWithUrl(String urlWithExtraParams) {
final ReplicationCommand pushReplicationCommand = new ReplicationCommand.Builder()
.source(DATABASE_NAME)
.target(urlWithExtraParams)
.continuous(true)
.build();
EktorpAsyncTask pushReplication = new EktorpAsyncTask() {
@Override
protected void doInBackground() {
dbInstance.replicate(pushReplicationCommand);
}
};
pushReplication.execute();
final ReplicationCommand pullReplicationCommand = new ReplicationCommand.Builder()
.source(urlWithExtraParams)
.target(DATABASE_NAME)
.continuous(true)
.build();
EktorpAsyncTask pullReplication = new EktorpAsyncTask() {
@Override
protected void doInBackground() {
dbInstance.replicate(pullReplicationCommand);
}
};
pullReplication.execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment