Designer 10.7 | webMethods Mobile Development | Creating Business Logic for a Mobile Application | Using the Sync Component Object
 
Using the Sync Component Object
webMethods Mobile Suite provides capabilities to enable offline data synchronization. This means that a specific set of data can be transmitted from a device to a dedicated server, and vice versa, and conflicts are automatically resolved. With the Mobile Suite, the Mobile Support library does all the communication with the host and provides information when a data object is added, changed, or deleted. For more information about Mobile Support, see Developing Data Synchronization Solutions with webMethods Mobile Support, which is part of the Integration Server documentation.
Mobile Support, however, is only responsible for synchronizing the data with a server. In the application, the data still needs to be persisted to enable proper offline support. To facilitate the development with Mobile Support, Mobile Development builds a library on top to achieve the offline support and provides a SyncComponent object to configure and implement the connection. See Adding the SyncComponent Object and Services Object Reference.
When the SyncComponent object is added to a project, Mobile Development generates a number of API classes. After adding the SyncComponent object, it is therefore required to regenerate the API classes. The SyncComponent object itself behaves like a RESTful service and can be added to a RESTDataSource object as a REST method. Once the SyncComponent object has been added to the project, the singleton instance can be accessed using the AbstractApplicationController#getSyncClient method. You can thus start or stop the synchronization or even attach a com.softwareag.mobile.runtime.toolkit.delegates.ISyncClientListener to get information about status changes, for example, when the synchronization is about to start or if an exception has occurred.
When you use the SyncComponent object as a REST method for a RESTDataSource, the synchronization will start automatically. Otherwise, you have to start it programmatically by calling #start() on the common instance. Before starting, make sure that all credentials have been set. As known from RESTful services, the SyncComponent object is prepared to use the credentials placed on the common Session object. For more information about providing credentials, see the code snippet in Configuring a Session Object with Credentials.
To synchronize data, the SyncComponent object establishes a synchronization process:
1. First, it tries to load local data from the underlying SQLite database.
2. If no data is stored, it downloads all data from the dedicated server. If data is stored, it asks the server whether there are any updates for this data set.
3. Incoming data is stored in the database. It performs delete, update and add operations to keep the local data up-to-date.
When the synchronization process is complete, it is restarted after a specific update interval, as specified in the application model or as set programmatically. This ensures an ongoing synchronization during the entire run time of the application. Synchronization only stops if an exception occurs with the communication, for example, if there is no connection to the network. For such a case, you have to implement an ISyncClientListener and restart the SyncComponent object.
Related Topics