Interface DiscardUnsyncedChangesStrategy

  • All Superinterfaces:
    SyncClientResetStrategy

    public interface DiscardUnsyncedChangesStrategy
    extends SyncClientResetStrategy
    Strategy that automatically resolves a Client Reset by discarding any unsynced data, but otherwise keep the Realm open. Any changes will be reported through the normal collection and object notifications.

    A synced Realm may need to be reset because the MongoDB Realm Server encountered an error and had to be restored from a backup or because it has been too long since the client connected to the server so the server has rotated the logs.

    The Client Reset thus occurs because the server does not have the full information required to bring the Client fully up to date.

    The discard unsynced changes reset process is as follows: when a client reset is triggered the onBeforeReset(Realm) callback is invoked, providing an instance of the Realm before the reset and another after the reset, both read-only. Once the reset has concluded the callback onAfterReset(Realm, Realm) would be invoked with an instance of the final Realm.

    In the event that discarding the unsynced data is not enough to resolve the reset the onError(SyncSession, ClientResetRequiredError) would be invoked, it allows to manually resolve the reset as it would be done in ManuallyRecoverUnsyncedChangesStrategy.onClientReset(SyncSession, ClientResetRequiredError).

    • Method Detail

      • onBeforeReset

        void onBeforeReset​(Realm realm)
        Callback that indicates a Client Reset is about to happen. It provides with a frozen instance of the Realm that is will be reset.
        Parameters:
        realm - frozen Realm in its state before the reset.
      • onAfterReset

        void onAfterReset​(Realm before,
                          Realm after)
        Callback invoked once the Client Reset happens. It provides of two Realm instances, a frozen one displaying the state before the reset and a regular Realm with the current state, that can be used to recover objects from the reset.
        Parameters:
        before - Realm frozen Realm in the before after the reset.
        after - Realm Realm after the reset.