SyncSession

interface SyncSession

A session controls how data is synchronized between a single Realm on the device and MongoDB on the server.

A SyncSession is created by opening a Realm instance using a SyncConfiguration. Once a session has been created, it will continue to exist until the app is closed or the Realm is closed.

A session is controlled by Realm, but can provide additional information in case of errors. These errors are passed along in the ErrorHandler.

When creating a session, Realm will establish a connection to the server. This connection is controlled by Realm and might be shared between multiple sessions.

The session itself has a different lifecycle than the underlying connection.

The SyncSession object is thread safe.

Types

ErrorHandler
Link copied to clipboard
fun interface ErrorHandler

Interface used to report any session errors.

State
Link copied to clipboard
enum State : Enum<SyncSession.State>

The possible states for SyncSession to be.

Functions

connectionStateAsFlow
Link copied to clipboard
abstract fun connectionStateAsFlow(): <ERROR CLASS><ConnectionStateChange>

Create a Flow of ConnectionStateChange-events to receive notifications of updates to the session's connection state.

downloadAllServerChanges
Link copied to clipboard
abstract suspend fun downloadAllServerChanges(timeout: Duration = Duration.INFINITE): Boolean

Calling this method will block until all known remote changes have been downloaded and applied to the Realm or the specified timeout is hit. This will involve network access, so calling this method should only be done from a non-UI thread.

pause
Link copied to clipboard
abstract fun pause()

Pauses synchronization with Atlas until the Realm is closed and re-opened again.

progressAsFlow
Link copied to clipboard
abstract fun progressAsFlow(direction: Direction, progressMode: ProgressMode): <ERROR CLASS><Progress>

Create a Flow of Progress-events that track either downloads or uploads done by the SyncSession.

resume
Link copied to clipboard
abstract fun resume()

Attempts to resume the session and activate synchronization with Atlas.

uploadAllLocalChanges
Link copied to clipboard
abstract suspend fun uploadAllLocalChanges(timeout: Duration = Duration.INFINITE): Boolean

Calling this method will block until all known local changes have been uploaded to the server or the specified timeout is hit. This will involve network access, so calling this method should only be done from a non-UI thread.

Properties

configuration
Link copied to clipboard
abstract val configuration: SyncConfiguration

The SyncConfiguration responsible for controlling the session.

connectionState
Link copied to clipboard
abstract val connectionState: ConnectionState

The current ConnectionState.

state
Link copied to clipboard
abstract val state: SyncSession.State

The current session state. See State for more details about each state.

user
Link copied to clipboard
abstract val user: User

The User used to authenticate the session on Atlas App Services.