
On Oct 24, 2014, at 3:29 AM, CouchbaseLover <sharess...@gmail.com> wrote:I agree that this would be very nice but how do you accomplish reading the sync?
On Nov 5, 2014, at 3:19 PM, Dominique Legault <deefac...@gmail.com> wrote:How could this be achieved using the phonegap app ?
{
continuous: true
source: "mydb"
status: "Idle"
target: "http://server.local/mydb"
task: "repl002"
type: "Replication"
}
On Nov 10, 2014, at 10:12 AM, Juan Hernandez <juanherna...@gmail.com> wrote:It's impossible to know if my local changes have been replicated already to the server as I don't know if the status "Idle" happened before or after I made those changes.
Maybe we could have the last Source sequence ID (Checkpoint) from the replication in the active tasks object.
What I would like to see is access to the Replication Change Listener through the REST API, similar to the Document Change Listener.
--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/JRZbjSSDd8s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/7EF26060-0180-474F-A157-564CB34221A6%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.
Maybe we could have the last Source sequence ID (Checkpoint) from the replication in the active tasks object.That sounds reasonable. (Do you know whether CouchDB's _active_tasks already includes this?) Please file an issue to request it.—Jens
{"progress":0,
"target":"openmoney",
"source":"https://sync.url",
"type":"Replication",
"status":"Processed 0 / 0 changes",
"task":"repl002"}
On Nov 11, 2014, at 1:04 PM, Dominique Legault <deefac...@gmail.com> wrote:How can it go back to 2 / 2 changes once it has hit 2 / 3 changes ?
The changes feed for documents only sends data when it changes, the active_tasks is different in that it sends data continuously.
How do I detect the various different states that the replication is in with the active_tasks API ?
How do I know if a change has completed ?
How can it go back to 2 / 2 changes once it has hit 2 / 3 changes ?
The changes feed for documents only sends data when it changes, the active_tasks is different in that it sends data continuously.
When I turn off access to the internet the stream of continuous responses stops.
How do I detect the various different states that the replication is in with the active_tasks API ?
Idle when there isn't a change ?
Active when changes are not equal ?
and Stopped when the stream stops ?
How do I know if a change has completed ?
do I track the number of changes I have made and compare that to the number of changes completed ?
On Monday, 10 November 2014 11:12:03 UTC-8, Jens Alfke wrote:
> On Nov 10, 2014, at 10:56 AM, Dominique <deefac...@gmail.com> wrote:
>
> What I would like to see is access to the Replication Change Listener through the REST API, similar to the Document Change Listener.
If you add "?feed=continuous" to _active_tasks it'll send push updates just like the _changes feed.
—Jens
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/24bf3b32-bb3a-4df4-ac5e-78481382345d%40googlegroups.com.
On Nov 11, 2014, at 2:08 PM, Traun Leyden <traun....@gmail.com> wrote:I'm not sure I understand this, can you describe it in more details? Are you saying that the HTTP response never finishes?
See inline responses below:
How can it go back to 2 / 2 changes once it has hit 2 / 3 changes ?That's definitely a bug. Can you file a github issue here and mention:
* Is it a pull or push replication?
* Which version of Couchbase Lite are you using? (or a link to where you downloaded it and I can probably figure out from there)* Is this sync'ing with a CouchDB database or a Sync Gateway?* Is it possible to put the database or an equivalent database on a public URL so that we can test against it and try to reproduce the issue?
phonegap plugin remove com.couchbase.lite.phonegap
phonegap local plugin add https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin.git
The changes feed for documents only sends data when it changes, the active_tasks is different in that it sends data continuously.
When I turn off access to the internet the stream of continuous responses stops.I'm not sure I understand this, can you describe it in more details? Are you saying that the HTTP response never finishes?
String status = String.format("Processed %d / %d changes", processed, total);
if (replicator.getStatus().name() != ReplicationStatus.REPLICATION_ACTIVE) {
status = replicator.getStatus().name();
}
String status = String.format("Processed %d / %d changes", processed, total);
if (! replicator.getStatus().name().equals( ReplicationStatus.REPLICATION_ACTIVE ) ) {
status = replicator.getStatus().name();
}
public Status do_GET_Document_active_tasks(Database _db, String _docID, String _attachmentName) {
return do_GET_active_tasks(_db, _docID, _attachmentName);
}
private boolean longpollReplication = false;
public Status do_GET_active_tasks(Database _db, String _docID, String _attachmentName) {
// http://wiki.apache.org/couchdb/HttpGetActiveTasks
String feed = getQuery("feed");
longpollReplication = "longpoll".equals(feed);
boolean continuous = !longpollReplication && "continuous".equals(feed);
String session_id = getQuery("session_id");
ChangeListener listener = new ChangeListener() {
ChangeListener self = this;
@Override
public void changed(ChangeEvent event) {
Map<String,Object> activity = getActivity( event.getSource() );
if (event.getTransition() != null ) {
activity.put("transition_source", event.getTransition().getSource());
activity.put("transition_destination", event.getTransition().getDestination());
activity.put("trigger", event.getTransition().getTrigger() );
Log.d(Log.TAG_ROUTER, "do_GET_active_tasks Transition [" + event.getTransition().getTrigger() + "] Source:" + event.getTransition().getSource() + ", Destination:" + event.getTransition().getDestination() );
}
if(longpollReplication) {
Log.w(Log.TAG_ROUTER, "Router: Sending longpoll replication response");
sendResponse();
if(callbackBlock != null) {
byte[] data = null;
try {
data = Manager.getObjectMapper().writeValueAsBytes(activity);
} catch (Exception e) {
Log.w(Log.TAG_ROUTER, "Error serializing JSON", e);
}
OutputStream os = connection.getResponseOutputStream();
try {
os.write(data);
os.close();
} catch (IOException e) {
Log.e(Log.TAG_ROUTER, "IOException writing to internal streams", e);
}
}
//remove this change listener because a new one will be added when this responds
event.getSource().removeChangeListener(self);
} else {
Log.w(Log.TAG_ROUTER, "Router: Sending continous replication change chunk");
sendContinuousReplicationChanges(activity);
}
}
};
List<Map<String,Object>> activities = new ArrayList<Map<String,Object>>();
for (Database db : manager.allOpenDatabases()) {
List<Replication> allReplicators = db.getAllReplications();
if(allReplicators != null) {
for (Replication replicator : allReplicators) {
Map<String,Object> activity = getActivity( replicator );
activities.add(activity);
if (continuous || longpollReplication) {
if (session_id != null) {
if (replicator.getSessionID().equals(session_id)){
replicator.addChangeListener(listener);
}
} else {
replicator.addChangeListener(listener);
}
}
}
}
}
if (continuous || longpollReplication) {
connection.setChunked(true);
connection.setResponseCode(Status.OK);
sendResponse();
if (continuous && !activities.isEmpty()) {
for (Map<String,Object> activity : activities) {
sendContinuousReplicationChanges(activity);
}
}
// Don't close connection; more data to come
return new Status(0);
} else {
connection.setResponseBody(new Body(activities));
return new Status(Status.OK);
}
}
private Map<String,Object> getActivity(Replication replicator) {
Map<String,Object> activity = new HashMap<String,Object>();
String source = replicator.getRemoteUrl().toExternalForm();
String target = replicator.getLocalDatabase().getName();
if(!replicator.isPull()) {
String tmp = source;
source = target;
target = tmp;
}
int processed = replicator.getCompletedChangesCount();
int total = replicator.getChangesCount();
String status = String.format("Processed %d / %d changes", processed, total);
if (! replicator.getStatus().name().equals( ReplicationStatus.REPLICATION_ACTIVE.name() ) ) {
status = replicator.getStatus().name();
}
int progress = (total > 0) ? Math.round(100 * processed / (float)total) : 0;
activity.put("type", "Replication");
activity.put("task", replicator.getSessionID());
activity.put("source", source);
activity.put("target", target);
if (replicator.getLastError() != null) {
String msg = String.format("Replicator error: %s. Repl: %s. Source: %s, Target: %s",
replicator.getLastError(), replicator, source, target);
Log.e(Log.TAG_ROUTER, msg);
Throwable error = replicator.getLastError();
int statusCode = 400;
if (error instanceof HttpResponseException) {
statusCode = ((HttpResponseException)error).getStatusCode();
}
Object[] errorObjects = new Object[]{ statusCode, replicator.getLastError().toString() };
activity.put("error", errorObjects);
activity.put("status", Replication.ReplicationStatus.REPLICATION_STOPPED);
activity.put("progress", null);
activity.put("change_count", null);
activity.put("completed_change_count", null);
} else {
activity.put("status", status);
activity.put("progress", progress);
activity.put("change_count", total);
activity.put("completed_change_count", processed);
}
return activity;
}
public void sendContinuousReplicationChanges(Map<String,Object> activity) {
try {
String jsonString = Manager.getObjectMapper().writeValueAsString(activity);
if(callbackBlock != null) {
byte[] json = (jsonString + "\n").getBytes();
OutputStream os = connection.getResponseOutputStream();
try {
os.write(json);
os.flush();
} catch (Exception e) {
Log.e(Log.TAG_ROUTER, "IOException writing to internal streams", e);
}
}
} catch (Exception e) {
Log.w("Unable to serialize change to JSON", e);
}
}On Nov 16, 2014, at 1:33 PM, Dominique Legault <deefac...@gmail.com> wrote:I have finally been dynamically update my UI using phonegap. I had to update couchbase-lite-java library REST API to implement the feed=continous and feed=longpoll parameters:
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/d05c7ef7-9861-464a-b9d0-2e187fdef3c1%40googlegroups.com.