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 callbackonAfterReset(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 inManuallyRecoverUnsyncedChangesStrategy.onClientReset(SyncSession, ClientResetRequiredError)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
onAfterReset(Realm before, Realm after)
Callback invoked once the Client Reset happens.void
onBeforeReset(Realm realm)
Callback that indicates a Client Reset is about to happen.void
onError(SyncSession session, ClientResetRequiredError error)
Callback that indicates the seamless Client reset couldn't complete.
-
-
-
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
- frozenRealm
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.
-
onError
void onError(SyncSession session, ClientResetRequiredError error)
Callback that indicates the seamless Client reset couldn't complete. It should be handled asManuallyRecoverUnsyncedChangesStrategy.onClientReset(SyncSession, ClientResetRequiredError)
.- Parameters:
session
-SyncSession
this error happened on.error
-ClientResetRequiredError
the specific Client Reset error.
-
-