Synchronization Sequence

Top  Previous  Next

This section describes the sequence of calls to different DeviceDriver methods by the server core during synchronization of the device with the server.

1.If device is suspended, synchronization is skipped.
2.If device dependency expression evaluates to false, synchronization is skipped and device switches to Offline connection status.
3.Driver's should shouldSynchronize() method is called. If it returns false (e.g. if device communication settings were not yet defined), synchronization is skipped.
4.If extended status is enabled, device's synchronization status switches to Connecting.
5.If isUsesConnections() method of the driver returns true:
5.1. If isConnected() returns false or system core requests reconnection to the hardware (e.g. because previous sync has failed and Interrupt Synchronization On Error is enabled), the system calls disconnect() (only if isConnected() is true) and then connect().
5.2. If connect() doesn't throw an exception, device switches to Online connection status.
6. Certain synchronization tasks called "connect-only" tasks may end at this point.
7. If extended status is enabled, device's synchronization status switches to Reading Metadata.
8. startSynchronization() is called.
9. If synchronization parameters request metadata reading (i.e. "full" synchronization is performed):
9.1. If driver supports groups (i.e. isUsesGroups() returns true) and groups has not yet been read from device (or driver was reset), readGroupDefinitions() method is called.
9.2. readVariableDefinitions() is called, new and changed definitions are added to the device context and cached in database. If driver supports groups, readVariableDefinitions(List<GroupDefinition>) method is called instead.
9.3. If synchronization settings of some newly added variable definitions have custom synchronization period, per-setting synchronization tasks are scheduled.
9.4. readFunctionDefinitions() is called, new and changed definitions are added to the device context and cached. If driver supports groups, readFunctionDefinitions(List<GroupDefinition>) method is called instead.
9.5. Corresponding Call Function action is added to device context for every new function definition.
9.6. readEventDefinitions() is called, new and changed definitions are added to the device context and cached. If driver supports groups, readEventDefinitions(List<GroupDefinition>) method is called instead.
9.7. If any of the above read methods throw a DisconnectionException, the error is logged, device switches to Offline connection status, driver's disconnect() method is called, and synchronization is terminated.
10. If extended status is enabled, device's synchronization status switches to Synchronizing Settings.
11. All device settings (or settings specified in the synchronization parameters) are synchronized with the server. Synchronization algorithm depends to the setting's synchronization mode. Server may call the following driver's methods at that point:
11.1. getVariableModificationTime() to get device-side modification timestamp for a setting. If modification timestamps are not supported by the hardware, this method should return null. In this case server will write setting value to the device if it was modified in the server cache and read it from the device otherwise.
11.2. readVariableValue() to read device-side value of a setting.
11.3. writeVariableValue() to write server-side value to the device.
11.4. updateVariableModificationTime() to store new modification timestamp in the device.
11.5. If any of the above methods throw a DisconnectionException, it is logged, device goes to Offline connection state, driver's disconnect() method is called, and synchronization is terminated.
11.6. If any of the above methods throw some other exception, it is logged, setting synchronization status is set to Error, and synchronization is terminated if Interrupt Synchronization On Error is enabled.
12. finishSynchronization() is called.
13. Device online and synchronization statuses are reevaluated.