Last active
December 24, 2015 22:59
-
-
Save tleyden/6876753 to your computer and use it in GitHub Desktop.
Kickoff replication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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