Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,19 @@ class WorkManagerReplicatorConfiguration private constructor(replConfig: Replica
companion object {
/**
* Factory method for WorkManagerReplicatorConfiguration.
* @deprecated Use from(collections: Set<CollectionConfiguration>, target: Endpoint)
*/
fun from(collections: Set<CollectionConfiguration>, target: Endpoint) =
WorkManagerReplicatorConfiguration(ReplicatorConfiguration(collections, target))

@Deprecated(
"Use from(collections: Set<CollectionConfiguration>, target: Endpoint)",
replaceWith = ReplaceWith("WorkManagerReplicatorConfiguration.from(collections: Set<CollectionConfiguration>, target: Endpoint)")
)
fun from(target: Endpoint) = WorkManagerReplicatorConfiguration(ReplicatorConfiguration(target))

/**
* Factory method for WorkManagerReplicatorConfiguration.
*/
fun from(collections: Set<CollectionConfiguration>, target: Endpoint) = WorkManagerReplicatorConfiguration(ReplicatorConfiguration(collections, target))

/**
* Factory method for WorkManagerReplicatorConfiguration.
Expand Down
2 changes: 2 additions & 0 deletions common/main/java/com/couchbase/lite/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private Replicator() { }
* Max wait time between retry attempts in seconds
*/
public static final int MAX_ATTEMPTS_WAIT_TIME = 300;
@Deprecated
public static final int MAX_ATTEMPT_WAIT_TIME = MAX_ATTEMPTS_WAIT_TIME;

/**
* Purge documents when a user loses access
Expand Down
46 changes: 42 additions & 4 deletions common/main/java/com/couchbase/lite/ReplicatorConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package com.couchbase.lite;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Map;

import com.couchbase.lite.internal.ImmutableReplicatorConfiguration;
import com.couchbase.lite.internal.utils.Preconditions;


public final class ReplicatorConfiguration extends AbstractReplicatorConfiguration {
Expand All @@ -28,6 +30,42 @@ public final class ReplicatorConfiguration extends AbstractReplicatorConfigurati
// Constructors
//---------------------------------------------

/**
* Create a Replicator Configuration for the given database and target endpoint.
*
* <p>When using this constructor, the default collection of the provided
* database will be automatically included in the configuration.</p>
*
* <p>If you do not intend to replicate the default collection, use
* ReplicatorConfiguration(Endpoint) instead, and explicitly add
* the intended collections to avoid unintended behavior.</p>
*
* @param database the database to be synchronized
* @param target the endpoint with which to synchronize it
* @deprecated Use ReplicatorConfiguration(java.util.Collection&lt;CollectionConfiguration&gt;, Endpoint)
*/
@Deprecated
public ReplicatorConfiguration(@NonNull Database database, @NonNull Endpoint target) {
super(
Preconditions.assertNotNull(database, "database"),
configureDefaultCollection(database),
target);
}

/**
* Create a Replicator Configuration for the given target endpoint
*
* <p>This constructor does not configure any collections by default.
* Use {@link #addCollection(Collection, CollectionConfiguration)} or
* {@link #addCollections(java.util.Collection, CollectionConfiguration)} to
* configure collections to replicate.</p>
*
* @param target the target endpoint
* @deprecated Use ReplicatorConfiguration(java.util.Collection&lt;CollectionConfiguration&gt;, Endpoint)
*/
@Deprecated
public ReplicatorConfiguration(@NonNull Endpoint target) { super(null, null, target); }

/**
* Creates a Replicator Configuration with a set of collection configurations and
* the target endpoint.
Expand All @@ -50,11 +88,11 @@ public ReplicatorConfiguration(@NonNull java.util.Collection<CollectionConfigura
ReplicatorConfiguration(@NonNull ImmutableReplicatorConfiguration config) { super(config); }

// For Kotlin
ReplicatorConfiguration(@NonNull Endpoint target, @NonNull Map<Collection, CollectionConfiguration> collections) {
ReplicatorConfiguration(@NonNull Endpoint target, @Nullable Map<Collection, CollectionConfiguration> collections) {
super(
AbstractDatabase.getDbForCollections(collections.keySet()),
collections,
target);
(collections == null) ? null : AbstractDatabase.getDbForCollections(collections.keySet()),
collections,
target);
}

@NonNull
Expand Down
178 changes: 176 additions & 2 deletions common/main/kotlin/com/couchbase/lite/ConfigurationFactories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//
package com.couchbase.lite

import com.couchbase.lite.internal.getCollectionConfigs
import java.security.cert.X509Certificate


Expand Down Expand Up @@ -75,9 +76,85 @@ val ReplicatorConfigurationFactory: ReplicatorConfiguration? = null
* @param acceptParentDomainCookies Advanced: accept cookies for parent domains.
*
* @see com.couchbase.lite.ReplicatorConfiguration
* @deprecated Use ReplicatorConfigurationFactory?.newConfig(Endpoint, Set<CollectionConfiguration>, ...)
*/
@Suppress("DEPRECATION")
@Deprecated(
"Use ReplicatorConfiguration?.newConfig(Set<CollectionConfiguration>, Endpoint ...)",
replaceWith = ReplaceWith("ReplicatorConfiguration?.newConfig(Set<CollectionConfiguration>, Endpoint ...)")
)
fun ReplicatorConfiguration?.newConfig(
target: Endpoint? = null,
collections: Map<out kotlin.collections.Collection<Collection>, CollectionConfiguration?>? = null,
type: ReplicatorType? = null,
continuous: Boolean? = null,
authenticator: Authenticator? = null,
headers: Map<String, String>? = null,
pinnedServerCertificate: X509Certificate? = null,
maxAttempts: Int? = null,
maxAttemptWaitTime: Int? = null,
heartbeat: Int? = null,
enableAutoPurge: Boolean? = null,
acceptParentDomainCookies: Boolean? = null
): ReplicatorConfiguration {
val endPt =
target ?: this?.target ?: throw IllegalArgumentException("A ReplicatorConfiguration must specify an endpoint")
val config = if (collections == null) {
ReplicatorConfiguration(endPt, getCollectionConfigs(this))
} else {
val rc = ReplicatorConfiguration(endPt)
// Lint will flip out if you try to use `forEach` here.
for (e: Map.Entry<kotlin.collections.Collection<Collection>, CollectionConfiguration?> in collections) {
rc.addCollections(e.key, e.value)
}
rc
}

copyReplConfig(
this,
config,
type,
continuous,
authenticator,
headers,
maxAttempts,
maxAttemptWaitTime,
heartbeat,
enableAutoPurge,
acceptParentDomainCookies
)

(pinnedServerCertificate
?: this?.pinnedServerX509Certificate)?.let { config.setPinnedServerX509Certificate(it) }

return config
}

/**
* Create a ReplicatorConfiguration, overriding the receiver's
* values with the passed parameters.
*
* Note: A document that is blocked by a document Id filter will not be auto-purged
* regardless of the setting of the enableAutoPurge property
*
* @param target (required) The replication target endpoint.
* @param collections a set of collections configurations.
* @param type replicator type: push, pull, or push and pull: default is push and pull.
* @param continuous continuous flag: true for continuous, false by default.
* @param authenticator connection authenticator.
* @param headers extra HTTP headers to send in all requests to the remote target.
* @param pinnedServerCertificate target server's SSL certificate.
* @param maxAttempts max retry attempts after connection failure.
* @param maxAttemptWaitTime max time between retry attempts (exponential backoff).
* @param heartbeat heartbeat interval, in seconds.
* @param enableAutoPurge auto-purge enabled.
* @param acceptParentDomainCookies Advanced: accept cookies for parent domains.
*
* @see com.couchbase.lite.ReplicatorConfiguration
*/

fun ReplicatorConfiguration?.newConfig(
collections : Set<CollectionConfiguration>,
collections: Set<CollectionConfiguration>,
target: Endpoint,
type: ReplicatorType? = null,
continuous: Boolean? = null,
Expand All @@ -90,7 +167,7 @@ fun ReplicatorConfiguration?.newConfig(
enableAutoPurge: Boolean? = null,
acceptParentDomainCookies: Boolean? = null
): ReplicatorConfiguration {
val config = ReplicatorConfiguration(this?.collections?:collections, target)
val config = ReplicatorConfiguration(this?.collectionConfigs?:collections, target)

copyReplConfig(
this,
Expand Down Expand Up @@ -127,3 +204,100 @@ fun ReplicatorConfiguration?.newConfig(
)
fun DatabaseConfiguration?.create(databasePath: String? = null) = this.newConfig(databasePath)

/**
* Create a ReplicatorConfiguration, overriding the receiver's
* values with the passed parameters:
*
* Note: A document that is blocked by a document Id filter will not be auto-purged
* regardless of the setting of the enableAutoPurge property
*
* Warning: This factory method configures only the default collection!
* Using it on a configuration that describes any collections other than the default
* will loose all information associated with those collections
*
* @param database the local database
* @param target (required) The replication endpoint.
* @param type replicator type: push, pull, or push and pull: default is push and pull.
* @param continuous continuous flag: true for continuous. False by default.
* @param authenticator connection authenticator.
* @param headers extra HTTP headers to send in all requests to the remote target.
* @param pinnedServerCertificate target server's SSL certificate.
* @param channels Sync Gateway channel names.
* @param documentIDs IDs of documents to be replicated: default is all documents.
* @param pushFilter filter for pushed documents.
* @param pullFilter filter for pulled documents.
* @param conflictResolver conflict resolver.
* @param maxAttempts max retry attempts after connection failure.
* @param maxAttemptWaitTime max time between retry attempts (exponential backoff).
* @param heartbeat heartbeat interval, in seconds.
* @param enableAutoPurge auto-purge enabled.
* @param acceptParentDomainCookies Advanced: accept cookies for parent domains.
*
* @see com.couchbase.lite.ReplicatorConfiguration
* @deprecated Use ReplicatorConfiguration?.newConfig(Set<CollectionConfiguration>, Endpoint ...)
*/
@Suppress("DEPRECATION")
@Deprecated(
"Use ReplicatorConfiguration?.newConfig(Set<CollectionConfiguration>, Endpoint ...)",
replaceWith = ReplaceWith("ReplicatorConfiguration?.newConfig(Set<CollectionConfiguration>, Endpoint ...)")
)
fun ReplicatorConfiguration?.create(
database: Database? = null,
target: Endpoint? = null,
type: ReplicatorType? = null,
continuous: Boolean? = null,
authenticator: Authenticator? = null,
headers: Map<String, String>? = null,
pinnedServerCertificate: ByteArray? = null,
channels: List<String>? = null,
documentIDs: List<String>? = null,
pushFilter: ReplicationFilter? = null,
pullFilter: ReplicationFilter? = null,
conflictResolver: ConflictResolver? = null,
maxAttempts: Int? = null,
maxAttemptWaitTime: Int? = null,
heartbeat: Int? = null,
enableAutoPurge: Boolean? = null,
acceptParentDomainCookies: Boolean? = null
): ReplicatorConfiguration {
// ReplicatorConfiguration.getDatabase throws an ISE on null database
val db = database ?: try {
this?.database
} catch (e: CouchbaseLiteError) {
null
}
?: throw IllegalArgumentException("A ReplicatorConfiguration must specify a database")
checkDbCollections(db, this?.collections)

val config = ReplicatorConfiguration(
db,
target ?: this?.target ?: throw IllegalArgumentException("A ReplicatorConfiguration must specify an endpoint")
)

copyReplConfig(
this,
config,
type,
continuous,
authenticator,
headers,
maxAttempts,
maxAttemptWaitTime,
heartbeat,
enableAutoPurge,
acceptParentDomainCookies
)

copyLegacyReplConfig(
this,
config,
pinnedServerCertificate,
channels,
documentIDs,
pushFilter,
pullFilter,
conflictResolver
)

return config
}
Loading
Loading