If you look at com.couchbase.lite.AbstractDatabase’s close method, it will throw an exception if you have any active Replicator or LiveQuery associated with the database.
if (activeReplications.size() > 0) {
throw new CouchbaseLiteException(
"Cannot close the database. Please stop all of the replicators before closing the database.",
CBLError.Domain.CBLErrorDomain, CBLError.Code.CBLErrorBusy);
}
if (activeLiveQueries.size() > 0) {
throw new CouchbaseLiteException(
"Cannot close the database. Please remove all of the query listeners before closing the database.",
CBLError.Domain.CBLErrorDomain, CBLError.Code.CBLErrorBusy);
}
The user jean-maxime wrote about tracking active replicators in client code (Replicator with couchbase lite android 2.0) and from the responses given, it sounds like this is something the clients have to do.
It seems overly complicated and redundant to track Replicator and Query instances in client code instead of directly using something like activeReplications and activeLiveQueries as in the snippet above. Is there a way to avoid writing my own (thread-safe!) data structures for this? What’s the best practice to ensure that a database is the correct state to be closed?
Edit: using Android and Couchbase Lite 2.0.0