Replication

Replication

A Couchbase Lite pull or push Replication between a local and a remote Database.

Syntax


@interface CBLReplication : NSObject
class CBLReplication : NSObject
public class Replication
public class Replication
public class Replication

Summary


Constants
String
The name of the event raised by a Replication in response to a change in any of the following properties change: status, running, error, completed, total.
Events
The type of event raised by a Replication when any of the following properties change: status, running, error, completed, total.
Enums
Describes the status of a Replication.
Properties
Authenticator
authenticator { get; set; }
Gets or sets the Authenticator used to do authentication for network connections.
int
changesCount { get; }
If the Replication is active, gets the number of changes to be processed, otherwise 0.
String[]
channels { get; set; }
Gets or sets the list of Sync Gateway channel names to filter by for pull Replications. A null value means no filtering, and all available channels will be replicated. Only valid for pull replications whose source database is on a Couchbase Sync Gateway server. This is a convenience property that just sets the values of filter and filterParams.
int
If the Replication is active, gets the number of completed changes that have been processed, otherwise 0.
boolean
continuous { get; set; }
Gets or sets whether the Replication operates continuously, replicating changes as the source Database is modified.
boolean
createTarget { get; set; }
Gets or sets whether the target Database should be created if it doesn't already exist. This only has an effect if the target supports it.
String[]
docIds { get; set; }
Gets or sets the ids of the Documents to replicate.
String
filter { get; set; }
Gets or sets the name of an optional filter function to run on the source Database. Only documents for which the function returns true are replicated.
Map<String, String>
filterParams { get; set; }
Gets or sets the parameters to pass to the filter function.
Map<String, String>
headers { get; set; }
Gets or sets the extra HTTP headers to send in Replication requests to the remote Database.
boolean
isPull { get; }
Gets whether the Replication pulls from, as opposed to pushes to, the target.
boolean
isRunning { get; }
Gets whether the Replication is running. Continuous Replications never actually stop, instead they go idle waiting for new data to appear.
Error
lastError { get; }
Gets the last error, if any, that occurred since the Replication was started.
Database
localDatabase { get; }
Gets the local Database being replicated to/from.
The IDs of documents that have local changes that have not yet been pushed to the server by this replication. This only considers documents that this replication would push: documents that aren't matched by its filter or documentIDs (if any) are ignored. If the replication hasn't started yet, or if it's encountered an error, or if it's not a push replication at all, the value of this property is nil.
URL
remoteUrl { get; }
Gets the remote URL being replicated to/from.
ReplicationStatus
status { get; }
Gets the Replication's current status.
Methods
void
Adds a Database change delegate that will be called whenever the Replication changes.
boolean
Deletes any persistent credentials (passwords, auth tokens...) associated with this replication's CBLAuthenticator. Also removes session cookies from the cookie store.
void
deleteCookie(String name)
Deletes an HTTP cookie for the Replication.
bool
isDocumentPending(Document document)
Returns YES if a document has local changes that this replication will push to its server, but hasn't yet. This only considers documents that this replication would push: it returns NO for a document that isn't matched by its filter or documentIDs, even if that document has local changes.
void
Removes the specified delegate as a listener for the Replication change event.
void
Restarts the Replication.
void
setCookie(String name, String value, String path, Date expirationDate, boolean secure, boolean httpOnly)
Sets an HTTP cookie for the Replication.
void
start()
Starts the Replication.
void
stop()
Stops the Replication.
Delegates
void
ChangeDelegate(ChangeEvent event)
A delegate that can be used to listen for Replication changes.

Constants


String Change
The name of the event raised by a Replication in response to a change in any of the following properties change: status, running, error, completed, total.

Syntax

extern NSString * const kCBLReplicationChangeNotification
let kCBLReplicationChangeNotification: String!
Not applicable.
Not applicable.
Not applicable.

Events


event ChangeEvent
The type of event raised by a Replication when any of the following properties change: status, running, error, completed, total.

Syntax

@interface NSNotification : NSObject <NSCopying, NSCoding>
class NSNotification : NSObject, NSCopying, NSCoding
public interface ChangeEvent
public interface ChangeEvent
public class ReplicationChangeEventArgs : EventArgs

Enums


ReplicationStatus
Describes the status of a Replication.

Values

Stopped The Replication is finished or hit a fatal error.
Offline The remote host is currently unreachable.
Idle The continuous Replication is caught up and waiting for more changes.
Active The Replication is actively transferring data.

Syntax

typedef enum {
   kCBLReplicationStopped,
   kCBLReplicationOffline,
   kCBLReplicationIdle,
   kCBLReplicationActive
} CBLReplicationStatus;
enum CBLReplicationStatus: Int {
   case kCBLReplicationStopped
   case kCBLReplicationOffline
   case kCBLReplicationIdle
   case kCBLReplicationActive
}
public enum ReplicationStatus {
 STOPPED,
 OFFLINE,
 IDLE,
 ACTIVE
}
public enum ReplicationStatus {
 STOPPED,
 OFFLINE,
 IDLE,
 ACTIVE
}
public enum ReplicationStatus {
    Stopped,
    Offline,
    Idle,
    Active
}

Properties


Authenticator authenticator { get; set; }
Gets or sets the Authenticator used to do authentication for network connections.

Syntax

@property (readwrite) CBLAuthenticator * authenticator
var authenticator: CBLAuthenticator!
public Authenticator getAuthenticator()
public void setAuthenticator(Authenticator authenticator)
public Authenticator getAuthenticator()
public void setAuthenticator(Authenticator authenticator)
public Authenticator Authenticator { get; set; }
int changesCount { get; }
If the Replication is active, gets the number of changes to be processed, otherwise 0.

Syntax

@property (readonly) NSInteger total
var changesCount: UInt32 { get }
public int getChangesCount()
public int getChangesCount()
public int ChangesCount { get; }
String[] channels { get; set; }
Gets or sets the list of Sync Gateway channel names to filter by for pull Replications. A null value means no filtering, and all available channels will be replicated. Only valid for pull replications whose source database is on a Couchbase Sync Gateway server. This is a convenience property that just sets the values of filter and filterParams.

Syntax

@property (readwrite) NSArray * channels
var channels: [AnyObject]!
public List<String> getChannels()
public void setChannels(List<String> channels)
public List<String> getChannels()
public void setChannels(List<String> channels)
public IEnumerable<String> Channels { get; set; }
int completedChangesCount { get; }
If the Replication is active, gets the number of completed changes that have been processed, otherwise 0.

Syntax

@property (readonly) NSInteger completed
var completedChangesCount: UInt32 { get }
public int getCompletedChangesCount()
public int getCompletedChangesCount()
public int CompletedChangesCount { get; }
boolean continuous { get; set; }
Gets or sets whether the Replication operates continuously, replicating changes as the source Database is modified.

Syntax

@property (readwrite) BOOL continuous
var continuous: Bool
public boolean isContinuous()
public void setContinuous(boolean continuous)
public boolean isContinuous()
public void setContinuous(boolean continuous)
public Boolean Continuous { get; set; }
boolean createTarget { get; set; }
Gets or sets whether the target Database should be created if it doesn't already exist. This only has an effect if the target supports it.

Syntax

@property (readwrite) BOOL createTarget
var createTarget: Bool
public boolean shouldCreateTarget()
public void setCreateTarget(boolean createTarget)
public boolean shouldCreateTarget()
public void setCreateTarget(boolean createTarget)
public Boolean CreateTarget { get; set; }
String[] docIds { get; set; }
Gets or sets the ids of the Documents to replicate.

Syntax

@property (readwrite) NSArray * docIds
var docIds: [AnyObject]!
public List<String> getDocIds()
public void setDocIds(List<String> docIds)
public List<String> getDocIds()
public void setDocIds(List<String> docIds)
public IEnumerable<String> DocIds { get; set; }
String filter { get; set; }
Gets or sets the name of an optional filter function to run on the source Database. Only documents for which the function returns true are replicated.

Syntax

@property (readwrite) NSString * filter
var filter: String!
public String getFilter()
public void setFilter(String filter)
public String getFilter()
public void setFilter(String filter)
public String Filter { get; set; }
Map<String, String> filterParams { get; set; }
Gets or sets the parameters to pass to the filter function.

Syntax

@property (readwrite) NSDictionary * filterParams
var filterParams: [NSObject : AnyObject]!
public Map<String, String> getFilterParams()
public void setFilterParams(Map<String, String> filterParams)
public Map<String, String> getFilterParams()
public void setFilterParams(Map<String, String> filterParams)
public Dictionary<String, String> FilterParams { get; set; }
Map<String, String> headers { get; set; }
Gets or sets the extra HTTP headers to send in Replication requests to the remote Database.

Syntax

@property (readwrite) NSDictionary * headers
var headers: [NSObject : AnyObject]!
public Map<String, String> getHeaders()
public void setHeaders(Map<String, String> headers)
public Map<String, String> getHeaders()
public void setHeaders(Map<String, String> headers)
public Dictionary<String, String> Headers { get; set; }
boolean isPull { get; }
Gets whether the Replication pulls from, as opposed to pushes to, the target.

Syntax

@property (readonly) BOOL pull
var pull: Bool { get }
public boolean isPull()
public boolean isPull()
public Boolean IsPull { get; }
boolean isRunning { get; }
Gets whether the Replication is running. Continuous Replications never actually stop, instead they go idle waiting for new data to appear.

Syntax

@property (readonly) BOOL running
var running: (Bool) { get }
public boolean isRunning()
public boolean isRunning()
public Boolean IsRunning { get; }
Error lastError { get; }
Gets the last error, if any, that occurred since the Replication was started.

Syntax

@property (readonly) NSError * lastError
var lastError: NSError! { get }
public Throwable getLastError()
public Throwable getLastError()
public Exception LastError { get; }
Database localDatabase { get; }
Gets the local Database being replicated to/from.

Syntax

@property (readonly) CBLDatabase * localDatabase
vat localDatabase: CBLDatabase! { get } 
public Database getLocalDatabase()
public Database getLocalDatabase()
public Database LocalDatabase { get; }
pendingDocumentIDs { get; }
The IDs of documents that have local changes that have not yet been pushed to the server by this replication. This only considers documents that this replication would push: documents that aren't matched by its filter or documentIDs (if any) are ignored. If the replication hasn't started yet, or if it's encountered an error, or if it's not a push replication at all, the value of this property is nil.

Syntax

@property (readonly, nullable) NSSet* pendingDocumentIDs;
var pendingDocumentIDs: Set { get }
public Set getPendingDocumentIDs() { get; }
public Set getPendingDocumentIDs() { get; }
public ICollection GetPendingDocumentIDs()
URL remoteUrl { get; }
Gets the remote URL being replicated to/from.

Syntax

@property (readonly) NSURL * remoteUrl
var remoteUrl: NSURL! { get }
public URL getRemoteUrl()
public URL getRemoteUrl()
public Uri RemoteUrl { get; }
ReplicationStatus status { get; }
Gets the Replication's current status.

Syntax

@property (readonly) ReplicationStatus * status
var status: ReplicationStatus { get }
public ReplicationStatus getStatus()
public ReplicationStatus getStatus()
public ReplicationStatus Status { get; }

Methods


void addChangeListener( ChangeDelegate delegate)
Adds a Database change delegate that will be called whenever the Replication changes.

Parameters

delegate The Replication change delegate to add.

Syntax

NSNotificationCenter -(void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:kCBLReplicationChangeNotification object:(id)notificationSender
NSNotificationCenter func addObserver(observer: AnyObject, selector: Selector, name: kCBLReplicationChangeNotification, object: AnyObject?)
public void addChangeListener(ChangeListener listener)
public void addChangeListener(ChangeListener listener)
public event EventHandler<ReplicationChangeEventArgs> Change
boolean clearAuthenticationStores()
Deletes any persistent credentials (passwords, auth tokens...) associated with this replication's CBLAuthenticator. Also removes session cookies from the cookie store.

Syntax

- (BOOL) clearAuthenticationStores: (NSError**)outError;
func clearAuthenticationStores(outError: NSError) -> Bool
public boolean clearAuthenticationStores()
public boolean clearAuthenticationStores()
public bool clearAuthenticationStores()
void deleteCookie(String name)
Deletes an HTTP cookie for the Replication.

Parameters

name The name of the cookie.

Syntax

-(void)deleteCookieNamed:(NSString *)name
func deleteCookieNamed(name: String!)
public void deleteCookie(String name)
public void deleteCookie(String name)
public void DeleteCookie(String name)
bool isDocumentPending(Document document)
Returns YES if a document has local changes that this replication will push to its server, but hasn't yet. This only considers documents that this replication would push: it returns NO for a document that isn't matched by its filter or documentIDs, even if that document has local changes.

Parameters

document A document.

Syntax

-(bool)isDocumentPending:(CBLDocument* )document
func isDocumentPending(document: CBLDocument!)
public boolean isDocumentPending(Document document)
public boolean isDocumentPending(Document document)
public bool IsDocumentPending(Document document)
void removeChangeListener( ChangeDelegate delegate)
Removes the specified delegate as a listener for the Replication change event.

Parameters

delegate The Replication change delegate to remove.

Syntax

NSNotificationCenter -(void)removeObserver:(id)observer name:kCBLReplicationChangeNotification object:(id)anObject
NSNotificationCenter func removeObserver:(observer: AnyObject, name: kCBLReplicationChangeNotification, object: AnyObject?)
public void removeChangeListener(ChangeListener listener)
public void removeChangeListener(ChangeListener listener)
public event EventHandler<ReplicationChangeEventArgs> Change
void restart()
Restarts the Replication.

Syntax

-(void)restart
func restart()
public void restart()
public void restart()
public void Retart()
void setCookie(String name, String value, String path, Date expirationDate, boolean secure, boolean httpOnly)
Sets an HTTP cookie for the Replication.

Parameters

name The name of the cookie.
value The value of the cookie.
path The path attribute of the cookie.
expirationDate The expiration date of the cookie.
secure Whether the cookie should only be sent using a secure protocol (e.g. HTTPS).
httpOnly Whether the cookie should only be used when transmitting HTTP, or HTTPS, requests thus restricting access from other, non-HTTP APIs.

Syntax

-(void)setCookieNamed:(NSString *)name withValue:(NSString *)value path:(NSString *)path expirationDate:(NSDate *)expirationDate secure:(BOOL)secure httpOnly:(BOOL)httpOnly
func setCookieNamed(name: String!, withValue: String!, path: String!, expirationDate: NSDate!, secure: Bool)
public void setCookie(String name, String value, String path, Date expirationDate, boolean secure, boolean httpOnly)
public void setCookie(String name, String value, String path, long maxAge, boolean secure, boolean httpOnly)
public void setCookie(String name, String value, String path, Date expirationDate, boolean secure, boolean httpOnly)
public void setCookie(String name, String value, String path, long maxAge, boolean secure, boolean httpOnly)
public void SetCookie(String name, String value, String path, Date expirationDate, Boolean secure, Boolean httpOnly)
void start()
Starts the Replication.

Syntax

-(void)start
func start()
public void start()
public void start()
public void Start()
void stop()
Stops the Replication.

Syntax

-(void)stop
func stop()
public void stop()
public void stop()
public void Stop()

Delegates


void ChangeDelegate(ChangeEvent event)
A delegate that can be used to listen for Replication changes.

Parameters

event The Replication change event.

Syntax

-(void)changeNotification:(NSNotification *)notification
func changeNotification(notification: NSNotification)
public interface ChangeListener {
    void changed(ChangeEvent event);
}
public interface ChangeListener {
    void changed(ChangeEvent event);
}
Not applicable.