Greetings,
I want to display data from the couch database without using replication. I am using IBM cloudant and replication leads to a spike in my account usage, So how do I Sync with database, without replicating all the time?
Here is the sync code:
private void startSync() {
URL syncUrl;
try {
syncUrl = new URL(SYNC_URL);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Application application = (Application) Betslip.this.getApplication();
Replication pullReplication = application.getDatabase6().createPullReplication(syncUrl);
pullReplication.setContinuous(true);
Replication pushReplication = application.getDatabase6().createPushReplication(syncUrl);
pushReplication.setContinuous(true);
pullReplication.start();
pushReplication.start();
pullReplication.addChangeListener(new Replication.ChangeListener() {
@Override
public void changed(Replication.ChangeEvent event) {
Replication replication = event.getSource();
com.couchbase.lite.util.Log.d(TAGz, "Replication : " + replication + " changed.");
if (!replication.isRunning()) {
String msg = String.format("Replicator %s not running", replication);
com.couchbase.lite.util.Log.d(TAGz, msg);
} else {
int processed = replication.getCompletedChangesCount();
int total = replication.getChangesCount();
String msg = String.format("Replicator processed %d / %d", processed, total);
com.couchbase.lite.util.Log.d(TAGz, msg);
}
if (event.getError() != null) {
showError("No internet connection please put it on", event.getError());
}
}
});
pushReplication.addChangeListener(new Replication.ChangeListener() {
@Override
public void changed(Replication.ChangeEvent event) {
Replication replication = event.getSource();
com.couchbase.lite.util.Log.d(TAGz, "Replication : " + replication + " changed.");
if (!replication.isRunning()) {
String msg = String.format("Replicator %s not running", replication);
com.couchbase.lite.util.Log.d(TAGz, msg);
} else {
int processed = replication.getCompletedChangesCount();
int total = replication.getChangesCount();
String msg = String.format("Replicator processed %d / %d", processed, total);
com.couchbase.lite.util.Log.d(TAGz, msg);
}
if (event.getError() != null) {
showError("No internet connection", event.getError());
}
}
});
}