UltraLite User's Guide
Developing UltraLite Java Applications
Monitoring and canceling synchronization
In the class that implements UlSynchObserver, the UlSynchStatus object holds synchronization information. This object is filled by UltraLite with synchronization status information each time your updateSynchronizationStatus method is called.
The UlSynchStatus object has the following methods:
int getState() int getTableCount() int getTableIndex() Object getUserData() UlSynchOptions getSynchOptions() UlSqlStmt getStatement() int getErrorCode() boolean isOKToContinue() void cancelSynchronization()
These methods have the following meanings:
getState Returns a constant indicating the state of the synchronization. The constant is one of the following values:
STARTING No synchronization actions have yet been taken.
CONNECTING The synchronization stream has been built, but not yet opened.
SENDING_HEADER The synchronization stream has been opened, and the header is about to be sent.
SENDING_TABLE A table is being sent.
RECEIVING_UPLOAD_ACK An acknowledgement that the upload is complete is being received.
RECEIVING_TABLE A table is being received.
SENDING_DOWNLOAD_ACK An acknowledgement that download is complete is being sent.
DISCONNECTING The synchronization stream is about to be closed.
DONE Synchronization has completed successfully.
ERROR Synchronization has completed, but with an error.
For a description of the synchronization process, see The synchronization process.
getTableCount Returns the number of tables being synchronized. For each table there is a sending and receiving phase.
getTableIndex Returns the current table index for sending and receiving, starting at 0.
getUserData Returns the user data object.
getSynchOptions Returns the UlSynchOptions object.
getStatement Returns the statement that called the synchronization. The statement is an internal UltraLite statement, and this method is unlikely to be of practical use, but is included for completion.
getErrorCode When the synchronization state is set to ERROR, this method returns a diagnostic error code.
isOKToContinue This is set to false when cancelSynchronization is called. Otherwise, it is true.
cancelSynchronization The SQL exception SQLE_INTERRUPTED is set, and the synchronization stops as if a communications error had occurred. The observer is always called with either the DONE or ERROR state so that it can do proper cleanup.
The following code snippet illustrates a very simple observer:
void updateSynchronizationStatus( UlSynchStatus status ) { int state = status.getState(); System.out.println( "Sync status: " + state ); if( state == UlSynchStatus.SENDING_TABLE || state == UlSynchStatus.RECEIVING_TABLE ){ System.out.println( "send/receive table " + ( status.getTableIndex() + 1 ) + " of " + status.getTableCount() ); } }