TICDSSynchronizationOperation Class Reference
Inherits from | TICDSOperation : NSOperation |
Declared in | TICDSSynchronizationOperation.h |
Overview
The TICDSSynchronizationOperation
class describes a generic operation used by the TICoreDataSync
framework to synchronize changes made to a document.
In brief, a synchronization operation pulls down remote sync commands and changes, applies them locally (fixing any conflicts if necessary), and then pushes out the local set of unsynchronized sync changes.
In full, the operation carries out the following tasks: (Sync Command tasks are included below, although not yet implemented)
- Fetch an array containing UUID strings for each client device that has synchronized this document.
- For each client device that isn’t the current device:
- Fetch an array containing UUID strings for each available
SyncCommandSet
.
- Fetch an array containing UUID strings for each available
- Determine which
SyncCommandSet
s haven’t yet been applied locally. - If any
SyncCommandSet
s haven’t yet been applied, fetch them to theUnappliedSyncCommandSets
helper file directory. - Go through each
SyncCommandSet
and:- Carry out the command, determining whether synchronization can continue, or whether e.g. the entire store needs to be downloaded.
- Add the UUID of the set to the list of
AppliedSyncCommands.ticdsync
.
- If synchronization can continue, then for each client device that isn’t the current device:
- Fetch an array containing UUID strings for each available
SyncChangeSet
. - Determine which
SyncChangeSet
s haven’t yet been applied locally. - If any
SyncChangeSet
s haven’t yet been applied, fetch them to theUnappliedSyncChangeSets
helper file directory.
- Fetch an array containing UUID strings for each available
- Go through each
SyncChangeSet
and:- Check for conflicts against local changes made since the last synchronization.
- Fix any conflicts, and build an array of conflict warnings for issues that cannot be resolved.
- Apply each
SyncChange
in the set to the localWholeStore
. - Add the UUID of the set to the list of
AppliedSyncChangeSets.ticdsync
.
- If there are local
SyncCommand
s, renameUnsynchronizedSyncCommands.ticdsync
toUUID.synccmd
and push the file to the remote. - If there are local
SyncChange
s, renameUnsynchronizedSyncChanges.syncchg
toUUID.syncchd
and push the file to the remote. - Save this client’s file in the
RecentSyncs
directory for this document.
Operations are typically created automatically by the relevant sync manager.
You must use one of the subclasses of TICDSSynchronizationOperation
.
Tasks
Designated Initializer
-
– initWithDelegate:
Initialize a synchronization operation using a delegate that supports the
TICDSSynchronizationOperationDelegate
protocol.
Methods Overridden by Subclasses
-
– fetchRemoteIntegrityKey
Fetch the integrity key for this document.
-
– buildArrayOfClientDeviceIdentifiers
Build an array of
NSString
identifiers for all clients that have synchronized with this document. -
– buildArrayOfSyncChangeSetIdentifiersForClientIdentifier:
Build an array of
NSString
identifiers for eachSyncChangeSet
for the given client device. -
– fetchSyncChangeSetWithIdentifier:forClientIdentifier:toLocation:
Fetch a
SyncChangeSet
with a given identifier from a client’sSyncChanges
directory. -
– uploadLocalSyncChangeSetFileAtLocation:
Upload the specified sync changes file to the client device’s directory inside the document’s
SyncChanges
directory. -
– uploadRecentSyncFileAtLocation:
Upload the specified RecentSync file to the document’s
RecentSync
directory.
Callbacks
-
– fetchedRemoteIntegrityKey:
Pass back the remote integrity key for this document.
-
– builtArrayOfClientDeviceIdentifiers:
Pass back the assembled
NSArray
ofNSString
ClientDevice
identifiers. -
– builtArrayOfClientSyncChangeSetIdentifiers:forClientIdentifier:
Pass back the assembled
NSArray
ofNSString
SyncChangeSet
identifiers. -
– fetchedSyncChangeSetWithIdentifier:forClientIdentifier:modificationDate:withSuccess:
Indicate whether the download of the specified
SyncChangeSet
was successful. -
– uploadedLocalSyncChangeSetFileSuccessfully:
Indicate whether the upload of the sync change set file was successful.
-
– uploadedRecentSyncFileSuccessfully:
Indicate whether the upload of the RecentSync file was successful.
-
– contextForSyncChangesInUnappliedSyncChangeSet:
Releases any existing
unappliedSyncChangesContext
andunappliedSyncChangesCoreDataFactory
and sets new ones, linked to the set of sync changes specified in the given sync change set. -
– configureBackgroundApplicationContextForPersistentStoreCoordinator:
Configure a background context (for applying sync changes) using the same persistent store coordinator as the main application context.
Properties
-
paused
A boolean indicating whether the operation is currently paused awaiting an instruction to continue, e.g. for conflict resolution.
property -
mostRecentConflictResolutionType
The resolution type for the most recent conflict, set before resuming the operation after a conflict is detected.
property -
otherSynchronizedClientDeviceIdentifiers
An array of client identifiers for clients that synchronize with this document, excluding this client.
property -
otherSynchronizedClientDeviceSyncChangeSetIdentifiers
A dictionary of arrays; keys are client identifiers, values are sync change set identifiers for each of those clients.
property -
syncChangeSortDescriptors
The sort descriptors used to sort sync change objects in a
propertySyncChangeSet
before being applied. -
synchronizationWarnings
The warnings generated during this synchronization.
property -
integrityKey
The integrity key provided either by the client to check existing data matches integrity, or set during registration for new documents.
property
File Locations
-
localSyncChangesToMergeLocation
The location of the
propertySyncChangesBeingSynchronized.syncchg
file for this synchronization operation. -
appliedSyncChangeSetsFileLocation
The location of this document’s
propertyAppliedSyncChangeSets.ticdsync
file. -
unappliedSyncChangesDirectoryLocation
The location of the
propertyUnappliedSyncChanges
directory for this synchronization operation. -
unappliedSyncChangeSetsFileLocation
The location of this document’s
propertyUnappliedSyncChangeSets.ticdsync
file. -
localRecentSyncFileLocation
The location of the local RecentSync file to upload at the end of the synchronization process.
property
Managed Object Contexts and Factories
-
appliedSyncChangeSetsCoreDataFactory
A
propertyTICoreDataFactory
to access the contents of theAppliedSyncChangeSets.ticdsync
file. -
appliedSyncChangeSetsContext
The managed object context for the
propertyAppliedSyncChangeSets.ticdsync
file. -
unappliedSyncChangeSetsCoreDataFactory
A
propertyTICoreDataFactory
to access the contents of theUnappliedSyncChangeSets.ticdsync
file. -
unappliedSyncChangeSetsContext
The managed object context for the
propertyUnappliedSyncChangeSets.ticdsync
file. -
unappliedSyncChangesCoreDataFactory
A
propertyTICoreDataFactory
to access the contents of a single, unappliedSyncChangeSet
file. -
unappliedSyncChangesContext
The managed object context for the changes in a single, unapplied
propertySyncChangeSet
file. -
localSyncChangesToMergeCoreDataFactory
A
propertyTICoreDataFactory
to access the contents of the local, unsynchronized set ofSyncChange
s. -
localSyncChangesToMergeContext
The managed object context for the local, unsynchronized set of
propertySyncChange
s. -
primaryPersistentStoreCoordinator
The persistent store coordinator for the application – used to create a background application context, when needed.
property -
backgroundApplicationContext
The managed object context (tied to the application’s persistent store coordinator) in which
propertySyncChanges
are applied.
Completion
-
numberOfSyncChangeSetIDArraysToFetch
The total number of arrays of
propertySyncChangeSet
identifiers that need to be fetched. -
numberOfSyncChangeSetIDArraysFetched
The number of arrays of
propertySyncChangeSet
identifiers that have already been fetched. -
numberOfSyncChangeSetIDArraysThatFailedToFetch
The number of arrays of
propertySyncChangeSet
identifiers that failed to fetch because of an error. -
numberOfUnappliedSyncChangeSetsToFetch
The number of unapplied sync change sets that need to be fetched.
property -
numberOfUnappliedSyncChangeSetsFetched
The number of unapplied sync change sets that have already been fetched.
property -
numberOfUnappliedSyncChangeSetsThatFailedToFetch
The number of unapplied sync change sets that failed to fetch because of an error.
property
Properties
appliedSyncChangeSetsContext
The managed object context for the AppliedSyncChangeSets.ticdsync
file.
@property (nonatomic, retain) NSManagedObjectContext *appliedSyncChangeSetsContext
Declared In
TICDSSynchronizationOperation.h
appliedSyncChangeSetsCoreDataFactory
A TICoreDataFactory
to access the contents of the AppliedSyncChangeSets.ticdsync
file.
@property (nonatomic, retain) TICoreDataFactory *appliedSyncChangeSetsCoreDataFactory
Declared In
TICDSSynchronizationOperation.h
appliedSyncChangeSetsFileLocation
The location of this document’s AppliedSyncChangeSets.ticdsync
file.
@property (retain) NSURL *appliedSyncChangeSetsFileLocation
Declared In
TICDSSynchronizationOperation.h
backgroundApplicationContext
The managed object context (tied to the application’s persistent store coordinator) in which SyncChanges
are applied.
@property (nonatomic, retain) NSManagedObjectContext *backgroundApplicationContext
Declared In
TICDSSynchronizationOperation.h
integrityKey
The integrity key provided either by the client to check existing data matches integrity, or set during registration for new documents.
@property (retain) NSString *integrityKey
Declared In
TICDSSynchronizationOperation.h
localRecentSyncFileLocation
The location of the local RecentSync file to upload at the end of the synchronization process.
@property (retain) NSURL *localRecentSyncFileLocation
Declared In
TICDSSynchronizationOperation.h
localSyncChangesToMergeContext
The managed object context for the local, unsynchronized set of SyncChange
s.
@property (nonatomic, retain) NSManagedObjectContext *localSyncChangesToMergeContext
Declared In
TICDSSynchronizationOperation.h
localSyncChangesToMergeCoreDataFactory
A TICoreDataFactory
to access the contents of the local, unsynchronized set of SyncChange
s.
@property (nonatomic, retain) TICoreDataFactory *localSyncChangesToMergeCoreDataFactory
Declared In
TICDSSynchronizationOperation.h
localSyncChangesToMergeLocation
The location of the SyncChangesBeingSynchronized.syncchg
file for this synchronization operation.
@property (retain) NSURL *localSyncChangesToMergeLocation
Declared In
TICDSSynchronizationOperation.h
mostRecentConflictResolutionType
The resolution type for the most recent conflict, set before resuming the operation after a conflict is detected.
@property (assign) TICDSSyncConflictResolutionType mostRecentConflictResolutionType
Declared In
TICDSSynchronizationOperation.h
numberOfSyncChangeSetIDArraysFetched
The number of arrays of SyncChangeSet
identifiers that have already been fetched.
@property (nonatomic, assign) NSUInteger numberOfSyncChangeSetIDArraysFetched
Declared In
TICDSSynchronizationOperation.h
numberOfSyncChangeSetIDArraysThatFailedToFetch
The number of arrays of SyncChangeSet
identifiers that failed to fetch because of an error.
@property (nonatomic, assign) NSUInteger numberOfSyncChangeSetIDArraysThatFailedToFetch
Declared In
TICDSSynchronizationOperation.h
numberOfSyncChangeSetIDArraysToFetch
The total number of arrays of SyncChangeSet
identifiers that need to be fetched.
@property (nonatomic, assign) NSUInteger numberOfSyncChangeSetIDArraysToFetch
Declared In
TICDSSynchronizationOperation.h
numberOfUnappliedSyncChangeSetsFetched
The number of unapplied sync change sets that have already been fetched.
@property (nonatomic, assign) NSUInteger numberOfUnappliedSyncChangeSetsFetched
Declared In
TICDSSynchronizationOperation.h
numberOfUnappliedSyncChangeSetsThatFailedToFetch
The number of unapplied sync change sets that failed to fetch because of an error.
@property (nonatomic, assign) NSUInteger numberOfUnappliedSyncChangeSetsThatFailedToFetch
Declared In
TICDSSynchronizationOperation.h
numberOfUnappliedSyncChangeSetsToFetch
The number of unapplied sync change sets that need to be fetched.
@property (nonatomic, assign) NSUInteger numberOfUnappliedSyncChangeSetsToFetch
Declared In
TICDSSynchronizationOperation.h
otherSynchronizedClientDeviceIdentifiers
An array of client identifiers for clients that synchronize with this document, excluding this client.
@property (nonatomic, retain) NSArray *otherSynchronizedClientDeviceIdentifiers
Declared In
TICDSSynchronizationOperation.h
otherSynchronizedClientDeviceSyncChangeSetIdentifiers
A dictionary of arrays; keys are client identifiers, values are sync change set identifiers for each of those clients.
@property (retain) NSMutableDictionary *otherSynchronizedClientDeviceSyncChangeSetIdentifiers
Declared In
TICDSSynchronizationOperation.h
paused
A boolean indicating whether the operation is currently paused awaiting an instruction to continue, e.g. for conflict resolution.
@property (assign, getter=isPaused) BOOL paused
Declared In
TICDSSynchronizationOperation.h
primaryPersistentStoreCoordinator
The persistent store coordinator for the application – used to create a background application context, when needed.
@property (retain) NSPersistentStoreCoordinator *primaryPersistentStoreCoordinator
Declared In
TICDSSynchronizationOperation.h
syncChangeSortDescriptors
The sort descriptors used to sort sync change objects in a SyncChangeSet
before being applied.
@property (nonatomic, retain) NSArray *syncChangeSortDescriptors
Declared In
TICDSSynchronizationOperation.h
synchronizationWarnings
The warnings generated during this synchronization.
@property (retain) NSMutableArray *synchronizationWarnings
Declared In
TICDSSynchronizationOperation.h
unappliedSyncChangeSetsContext
The managed object context for the UnappliedSyncChangeSets.ticdsync
file.
@property (nonatomic, retain) NSManagedObjectContext *unappliedSyncChangeSetsContext
Declared In
TICDSSynchronizationOperation.h
unappliedSyncChangeSetsCoreDataFactory
A TICoreDataFactory
to access the contents of the UnappliedSyncChangeSets.ticdsync
file.
@property (nonatomic, retain) TICoreDataFactory *unappliedSyncChangeSetsCoreDataFactory
Declared In
TICDSSynchronizationOperation.h
unappliedSyncChangeSetsFileLocation
The location of this document’s UnappliedSyncChangeSets.ticdsync
file.
@property (retain) NSURL *unappliedSyncChangeSetsFileLocation
Declared In
TICDSSynchronizationOperation.h
unappliedSyncChangesContext
The managed object context for the changes in a single, unapplied SyncChangeSet
file.
@property (nonatomic, retain) NSManagedObjectContext *unappliedSyncChangesContext
Declared In
TICDSSynchronizationOperation.h
Instance Methods
buildArrayOfClientDeviceIdentifiers
Build an array of NSString
identifiers for all clients that have synchronized with this document.
- (void)buildArrayOfClientDeviceIdentifiers
Discussion
Call builtArrayOfClientDeviceIdentifiers:
when the array is built.
Declared In
TICDSSynchronizationOperation.h
buildArrayOfSyncChangeSetIdentifiersForClientIdentifier:
Build an array of NSString
identifiers for each SyncChangeSet
for the given client device.
- (void)buildArrayOfSyncChangeSetIdentifiersForClientIdentifier:(NSString *)anIdentifier
Parameters
- anIdentifier
The unique identifier of the client.
Discussion
Call builtArrayOfClientSyncChangeSetIdentifiers:forClientIdentifier:
when the array is built.
Declared In
TICDSSynchronizationOperation.h
builtArrayOfClientDeviceIdentifiers:
Pass back the assembled NSArray
of NSString
ClientDevice
identifiers.
- (void)builtArrayOfClientDeviceIdentifiers:(NSArray *)anArray
Parameters
- anArray
The array of identifiers. Pass
nil
if an error occurred.
Discussion
If an error occurred, call setError:
first, then specify nil
for anArray
.
Declared In
TICDSSynchronizationOperation.h
builtArrayOfClientSyncChangeSetIdentifiers:forClientIdentifier:
Pass back the assembled NSArray
of NSString
SyncChangeSet
identifiers.
- (void)builtArrayOfClientSyncChangeSetIdentifiers:(NSArray *)anArray forClientIdentifier:(NSString *)anIdentifier
Parameters
- anArray
The array of identifiers. Pass
nil
if an error occurred.
- anIdentifier
The client identifier for this array of
SyncChangeSet
identifiers.
Discussion
If an error occured, call setError:
first, then specify nil
for anArray
.
Declared In
TICDSSynchronizationOperation.h
configureBackgroundApplicationContextForPersistentStoreCoordinator:
Configure a background context (for applying sync changes) using the same persistent store coordinator as the main application context.
- (void)configureBackgroundApplicationContextForPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)aPersistentStoreCoordinator
Parameters
- aPersistentStoreCoordinator
The persistent store coordinator to use for the background context.
Declared In
TICDSSynchronizationOperation.h
contextForSyncChangesInUnappliedSyncChangeSet:
Releases any existing unappliedSyncChangesContext
and unappliedSyncChangesCoreDataFactory
and sets new ones, linked to the set of sync changes specified in the given sync change set.
- (NSManagedObjectContext *)contextForSyncChangesInUnappliedSyncChangeSet:(TICDSSyncChangeSet *)aChangeSet
Parameters
- aChangeSet
The
TICDSSyncChangeSet
object specifying the set of changes to use.
Return Value
A managed object context to access the sync changes.
Declared In
TICDSSynchronizationOperation.h
fetchRemoteIntegrityKey
Fetch the integrity key for this document.
- (void)fetchRemoteIntegrityKey
Discussion
This method must call fetchedRemoteIntegrityKey:
to provide the key.
Declared In
TICDSSynchronizationOperation.h
fetchSyncChangeSetWithIdentifier:forClientIdentifier:toLocation:
Fetch a SyncChangeSet
with a given identifier from a client’s SyncChanges
directory.
- (void)fetchSyncChangeSetWithIdentifier:(NSString *)aChangeSetIdentifier forClientIdentifier:(NSString *)aClientIdentifier toLocation:(NSURL *)aLocation
Parameters
- aChangeSetIdentifier
The identifier of the sync change set to fetch.
- aClientIdentifier
The identifier of the client who created the sync change set.
- aLocation
The location of the file to upload.
Discussion
This method must call fetchedSyncChangeSetsWithIdentifier:forClientIdentifier:withSuccess:
when finished.
Declared In
TICDSSynchronizationOperation.h
fetchedRemoteIntegrityKey:
Pass back the remote integrity key for this document.
- (void)fetchedRemoteIntegrityKey:(NSString *)aKey
Parameters
- aKey
The remote integrity key, or
nil
if an error occurred.
Discussion
If an error occurred, call setError:
first, then specify nil
for aKey
.
Declared In
TICDSSynchronizationOperation.h
fetchedSyncChangeSetWithIdentifier:forClientIdentifier:modificationDate:withSuccess:
Indicate whether the download of the specified SyncChangeSet
was successful.
- (void)fetchedSyncChangeSetWithIdentifier:(NSString *)aChangeSetIdentifier forClientIdentifier:(NSString *)aClientIdentifier modificationDate:(NSDate *)aDate withSuccess:(BOOL)success
Parameters
- aChangeSetIdentifier
The identifier for the change set to fetch.
- aClientIdentifier
The identifier of the client who uploaded the change set.
- aDate
The modification date of the change set.
- success
A Boolean indicating whether the sync change set file was downloaded or not.
Discussion
If not, call setError:
first, then specify NO
for success
.
If it was successful, you should supply the original modification date of the file.
Declared In
TICDSSynchronizationOperation.h
initWithDelegate:
Initialize a synchronization operation using a delegate that supports the TICDSSynchronizationOperationDelegate
protocol.
- (id)initWithDelegate:(NSObject<TICDSSynchronizationOperationDelegate> *)aDelegate
Parameters
- aDelegate
The delegate to use for this operation.
Return Value
An initialized synchronization operation.
Declared In
TICDSSynchronizationOperation.h
uploadLocalSyncChangeSetFileAtLocation:
Upload the specified sync changes file to the client device’s directory inside the document’s SyncChanges
directory.
- (void)uploadLocalSyncChangeSetFileAtLocation:(NSURL *)aLocation
Parameters
- aLocation
The location of the file to upload.
Discussion
This method must call uploadedLocalSyncChangeSetFileSuccessfully:
to indicate whether the creation was successful.
Declared In
TICDSSynchronizationOperation.h
uploadRecentSyncFileAtLocation:
Upload the specified RecentSync file to the document’s RecentSync
directory.
- (void)uploadRecentSyncFileAtLocation:(NSURL *)aLocation
Parameters
- aLocation
The location of the file to upload.
Discussion
This method must call uploadedRecentSyncFileSuccessfully:
to indicate whether the creation was successful.
Declared In
TICDSSynchronizationOperation.h
uploadedLocalSyncChangeSetFileSuccessfully:
Indicate whether the upload of the sync change set file was successful.
- (void)uploadedLocalSyncChangeSetFileSuccessfully:(BOOL)success
Parameters
- success
YES
if the sync change set file was uploaded, otherwiseNO
.
Discussion
If not, call setError:
first, then specify NO
for success
.
Declared In
TICDSSynchronizationOperation.h
uploadedRecentSyncFileSuccessfully:
Indicate whether the upload of the RecentSync file was successful.
- (void)uploadedRecentSyncFileSuccessfully:(BOOL)success
Parameters
- success
YES
if the RecentSync file was uploaded, otherwiseNO
.
Discussion
If not, call setError:
first, then specify NO
for success
.
Declared In
TICDSSynchronizationOperation.h