Class Replicator
An object that is responsible for the replication of data between two endpoints. The replication can set up to be pull only, push only, or both (i.e. pusher and puller are no longer separate) between a database and a URL or a database and another database on the same filesystem.
Inheritance
Implements
Inherited Members
Namespace: Couchbase.Lite.Sync
Assembly: Couchbase.Lite.dll
Syntax
public sealed class Replicator : IDisposable, IChangeObservable<ReplicatorStatusChangedEventArgs>, IDocumentReplicatedObservable, IChangeObservableRemovable
Constructors
| Improve this Doc View SourceReplicator(ReplicatorConfiguration)
Constructs a replicator based on the given ReplicatorConfiguration
Declaration
public Replicator(ReplicatorConfiguration config)
Parameters
Type | Name | Description |
---|---|---|
ReplicatorConfiguration | config | The configuration to use to create the replicator |
Properties
| Improve this Doc View SourceConfig
Gets the configuration that was used to create this Replicator
Declaration
public ReplicatorConfiguration Config { get; }
Property Value
Type | Description |
---|---|
ReplicatorConfiguration |
Exceptions
Type | Condition |
---|---|
CouchbaseLiteException | Thrown if the replicator configuration doesn't contain any collection. |
ServerCertificate
This property allows the developer to know what the current server certificate is when using TLS communication. The developer could save the certificate and pin the certificate next time when setting up the replicator to provide an SSH type of authentication.
Declaration
public X509Certificate2 ServerCertificate { get; }
Property Value
Type | Description |
---|---|
System.Security.Cryptography.X509Certificates.X509Certificate2 |
Status
Gets the current status of the Replicator
Declaration
public ReplicatorStatus Status { get; set; }
Property Value
Type | Description |
---|---|
ReplicatorStatus |
Methods
| Improve this Doc View SourceAddChangeListener(EventHandler<ReplicatorStatusChangedEventArgs>)
Adds a change listener on this replication object (similar to a C# event)
Declaration
public ListenerToken AddChangeListener(EventHandler<ReplicatorStatusChangedEventArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
System.EventHandler<ReplicatorStatusChangedEventArgs> | handler | The logic to run during the callback |
Returns
Type | Description |
---|---|
ListenerToken | A token to remove the handler later |
AddChangeListener(TaskScheduler, EventHandler<ReplicatorStatusChangedEventArgs>)
Adds a change listener on this replication object (similar to a C# event, but with the ability to specify a System.Threading.Tasks.TaskScheduler to schedule the handler to run on)
Declaration
public ListenerToken AddChangeListener(TaskScheduler scheduler, EventHandler<ReplicatorStatusChangedEventArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.Tasks.TaskScheduler | scheduler | The System.Threading.Tasks.TaskScheduler to run the |
System.EventHandler<ReplicatorStatusChangedEventArgs> | handler | The logic to run during the callback |
Returns
Type | Description |
---|---|
ListenerToken | A token to remove the handler later |
AddDocumentReplicationListener(EventHandler<DocumentReplicationEventArgs>)
Adds a documents ended listener on this replication object (similar to a C# event)
Declaration
public ListenerToken AddDocumentReplicationListener(EventHandler<DocumentReplicationEventArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
System.EventHandler<DocumentReplicationEventArgs> | handler | The logic to run during the callback |
Returns
Type | Description |
---|---|
ListenerToken | A token to remove the handler later |
Remarks
Make sure add documents ended listener on this replication object before starting the replicator.
AddDocumentReplicationListener(TaskScheduler, EventHandler<DocumentReplicationEventArgs>)
Adds a document ended listener on this replication object (similar to a C# event, but with the ability to specify a System.Threading.Tasks.TaskScheduler to schedule the handler to run on)
Declaration
public ListenerToken AddDocumentReplicationListener(TaskScheduler scheduler, EventHandler<DocumentReplicationEventArgs> handler)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.Tasks.TaskScheduler | scheduler | The System.Threading.Tasks.TaskScheduler to run the |
System.EventHandler<DocumentReplicationEventArgs> | handler | The logic to run during the callback |
Returns
Type | Description |
---|---|
ListenerToken | A token to remove the handler later |
Remarks
Make sure add documents ended listener on this replication object before starting the replicator.
Dispose()
Declaration
public void Dispose()
Finalize()
Finalizer
Declaration
protected void Finalize()
GetPendingDocumentIDs()
[DEPRECATED] Gets a list of document IDs that are going to be pushed, but have not been pushed yet
Declaration
[Obsolete("GetPendingDocumentIDs() is deprecated, please use GetPendingDocumentIDs(Collection collection)")]
public IImmutableSet<string> GetPendingDocumentIDs()
Returns
Type | Description |
---|---|
System.Collections.Immutable.IImmutableSet<System.String> | An immutable set of strings, each of which is a document ID |
Exceptions
Type | Condition |
---|---|
CouchbaseLiteException | Thrown if no push replication |
CouchbaseException | Thrown if an error condition is returned from LiteCore |
GetPendingDocumentIDs(Collection)
Gets a list of document IDs of docs in the given collection that are going to be pushed, but have not been pushed yet.
If the given collection is not part of the replication, an Invalid Parameter Exception will be thrown.
Declaration
public IImmutableSet<string> GetPendingDocumentIDs(Collection collection)
Parameters
Type | Name | Description |
---|---|---|
Collection | collection | The collection contains the list of document IDs of docs |
Returns
Type | Description |
---|---|
System.Collections.Immutable.IImmutableSet<System.String> | An immutable set of strings, each of which is a document ID |
Exceptions
Type | Condition |
---|---|
CouchbaseLiteException | Thrown if no push replication |
CouchbaseException | Thrown if an error condition is returned from LiteCore |
IsDocumentPending(String)
[DEPRECATED] Checks whether or not a document with the given ID has any pending revisions to push
Declaration
[Obsolete("IsDocumentPending(string documentID) is deprecated, please use IsDocumentPending(string documentID, Collection collection)")]
public bool IsDocumentPending(string documentID)
Parameters
Type | Name | Description |
---|---|---|
System.String | documentID | The document ID |
Returns
Type | Description |
---|---|
System.Boolean | A bool which represents whether or not the document with the corresponding ID has one or more pending revisions. |
Exceptions
Type | Condition |
---|---|
CouchbaseLiteException | Thrown if no push replication |
CouchbaseException | Thrown if an error condition is returned from LiteCore |
IsDocumentPending(String, Collection)
Checks whether or not a document with the given ID in the given collection is pending to push or not. If the given collection is not part of the replication, an Invalid Parameter Exception will be thrown.
Declaration
public bool IsDocumentPending(string documentID, Collection collection)
Parameters
Type | Name | Description |
---|---|---|
System.String | documentID | The document ID |
Collection | collection | The collection contains the doc with the given document ID |
Returns
Type | Description |
---|---|
System.Boolean | A bool which represents whether or not the document with the corresponding ID has one or more pending revisions. |
Exceptions
Type | Condition |
---|---|
CouchbaseLiteException | Thrown if no push replication |
CouchbaseException | Thrown if an error condition is returned from LiteCore |
RemoveChangeListener(ListenerToken)
Removes a previously added change listener via its ListenerToken and/or Removes a previously added documents ended listener via its ListenerToken
Declaration
public void RemoveChangeListener(ListenerToken token)
Parameters
Type | Name | Description |
---|---|---|
ListenerToken | token | The token received from AddChangeListener(TaskScheduler, EventHandler<ReplicatorStatusChangedEventArgs>) and/or The token received from AddDocumentReplicationListener(TaskScheduler, EventHandler<DocumentReplicationEventArgs>) |
Start()
Starts the replication
Declaration
public void Start()
Remarks
Warning
Calling this function inside of InBatch(Action) will result in a deadlock.
Start(Boolean)
Starts the replication with an option to reset the checkpoint.
Declaration
public void Start(bool reset)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | reset | Resets the local checkpoint of the replicator, meaning that it will read all changes since the beginning of time from the remote database. |
Remarks
Warning
Calling this function inside of InBatch(Action) will result in a deadlock.
Stop()
Stops a running replicator. This method returns immediately; when the replicator actually stops, the replicator will change its status's activity level to Stopped and the replicator change notification will be notified accordingly.
Declaration
public void Stop()
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |