The CallbackHandler interface is invoked when any database event occurs. A default callback handler is provided, which basically does nothing. You should implement a custom CallbackHandler to register important events. The callback is invoked on the thread that is processing the event. To receive callbacks for database changes, you must register a CallBackHandler with the generated database class, the entity class, or both. You can create a handler by extending the DefaultCallbackHandler class or by implementing the com.sybase.persistence.CallbackHandler interface.
In your handler, override the particular callback that you are interested in (for example, void onReplayFailure(java.lang.Object entity) ). The callback is executed in the thread that is performing the action (for example, replay). When you receive the callback, the particular activity is already complete.
Callback | Description |
---|---|
void onImport(java.lang.Object entity) |
This method is invoked when an import message is successfully applied to the local database. However, it is not committed. One message from server may have multiple import entities and they would be committed in one transaction for the whole message. Note:
Parameters:
|
void onLoginFailure() |
This method will be invoked when login failed for a beginOnlineLogin call. Note: Only the CallbackHandler
registered for package DB will be invoked.
|
void onLoginSuccess() |
This method is invoked when login succeeds for a beginOnlineLogin call. Note: Only
the CallbackHandler registered for package DB is
invoked.
|
void onReplayFailure(java.lang.Object entity) |
This method is invoked when a replay request fails. Note: CallbackHandlers registered for both the MBO
class of the entity and the Package DB are invoked.
Parameters:
|
void onReplaySuccess(java.lang.Object entity) |
This method is invoked when a replay request succeeds. onReplaySuccess is an MBO object instance that contains the data prior to the synchronization. You can use the Change Log API to find records that occur after the synchronization. Note: CallbackHandlers registered for both the MBO
class of the entity and the Package DB are invoked.
Parameters:
|
void onSearchFailure(java.lang.Object entity) |
This method is invoked when a back-end search fails. Note: CallbackHandlers
registered for both the MBO class of the entity and the Package
DB are
invoked.
Parameters:
|
void onSearchSuccess(java.lang.Object entity) |
This method is invoked when a back end search succeeds. Note: CallbackHandlers
registered for both the MBO class of the entity and the Package
DB are
invoked.
Parameters:
|
void onSubscribeFailure() |
This method is invoked when subscribe fails. Note: CallbackHandlers registered for both the MBO class of the
entity and the Package DB are invoked.
|
void onSubscribeSuccess() |
This method is invoked when subscribe succeeds. Note: Only
the CallbackHandler registered for the Package DB is
invoked.
|
int onSynchronize(ObjectList groups, SynchronizationContext context) |
This method is invoked at different stages of the synchronization. This method is called by the database class synchronize or beginSynchronize methods when the client initiates a synchronization, and is called again when the server responds to the client that synchronization has finished, or that synchronization failed. The status of the synchronization context, context.Status, specifies the stage of the synchronization. Parameters:
Returns: Either SynchronizationAction.CONTINUE or Synchronization.CANCEL. If
SynchronizationAction.CANCEL is returned, the
synchronize is cancelled if the status of the synchronization
context is one of the following.
|
void onSuspendSubscriptionFailure() |
This method is invoked when suspend subscription fails. Note: Only
the CallbackHandler registered for the Package DB is
invoked.
|
void onSuspendSubscriptionSuccess() |
This method is invoked when suspend subscription succeeds. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onResumeSubscriptionFailure() |
This method is invoked when resume subscription fails. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onResumeSubscriptionSuccess() |
This method is invoked when resume subscription succeeds. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onUnsubscribeFailure() |
This method is invoked when unsubscribe fails. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onUnsubscribeSuccess() |
This method is invoked when unsubscribe succeeds. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onMessageException(java.lang.Exception ex) |
This method is invoked when an exception occurs in the processing of a message. Note: In DefaultCallbackHandlers, onMessageException re-throws the
Exception so that the messaging layer can retry the message. The
application developer has the option to implement a custom
CallbackHandler that does not re-throw the exception, based on
exception types or other conditions, so that the message is not
retried.
Parameters:
|
void onSendMessageException() |
Notifies the application that an unrecoverable exception occurred while sending a message to the synchronization server. |
void onTransactionCommit() |
This method is invoked after a message is processed and committed. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onTransactionRollback() |
This method is invoked after a message is rolled back. It only happens when an Exception was thrown when processing the message, or from a custom Callback method. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onRecoverSuccess() |
This method is invoked when recover succeeds. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onRecoverFailure() |
This method is invoked when recover fails. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
void onSubscriptionEnd() |
This method is invoked when a subscription is re-registered or unsubscribed. This method deletes all MBO data on the device. Note: Only the CallbackHandler registered for the Package DB is
invoked.
|
onBulkDownloadFailure() | Invoked to notify the application that a bulk download subscription was submitted to the synchronization server and the download phase did not complete successfully. |
onBulkDownloadProgress() | Invoked to notify the application that a subscribe operation operation was submitted to the synchronization server and progress is being reported about the downloading of the initial data to the application. |
onBulkDownloadSuccess() | Invoked to notify the application that a bulk download subscription was submitted to the synchronization server and the download phase completed successfully. |
onInitialDataAvailable() | Invoked to notify the application that a subscribe operation operation was submitted to the synchronization server and, some time after onSubscribeSuccess was invoked, that the server has sent all initial data to the application. |
onPingFailure() | Invoked to notify the application of a failure to login to a synchronization server. |
onPingSuccess() | Invoked to notify the application of a successful login to a synchronization server. |
onPrepareToCommit() | Other callbacks in this interface (onImport, onReplay*, onSearch*) are invoked inside a database transaction. |
This code shows how to create and register a handler to receive callbacks:
public class MyCallbackHandler extends DefaultCallbackHandler { // implementation } CallbackHandler handler = new MyCallbackHandler(); <PkgName>DB.registerCallbackHandler(handler);