Class SyncSession
On this page
- io.realm.mongodb.sync
- Nested Class Summary
- Method Summary
- Inherited Methods
- Method Detail
- addConnectionChangeListener
- addDownloadProgressListener
- addUploadProgressListener
- downloadAllServerChanges
- getConfiguration
- getConnectionState
- getServerUrl
- getState
- getUser
- isConnected
- removeConnectionChangeListener
- removeProgressListener
- start
- stop
- uploadAllLocalChanges
io.realm.mongodb.sync
A session controls how data is synchronized between a single Realm on the device and the server Realm on the Realm Object Server.A Session 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 all threads using this SyncConfiguration closes their respective Realm s.
A session is controlled by Realm, but can provide additional information in case of errors. These errors are passed along in the SyncSession.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. It is possible to get insight into the connection using addConnectionChangeListener(ConnectionListener) and isConnected() .
The session itself has a different lifecycle than the underlying connection. The state of the session can be found using getState() .
The SyncSession object is thread safe.
Nested Class Summary
Modifier and Type | Class and Description |
---|---|
public static final | |
public static interface | |
public static interface |
Method Summary
Modifier and Type | Method and Description |
---|---|
public synchronized void | Adds a listener tracking changes to the connection backing this session. |
public synchronized void | Adds a progress listener tracking changes that need to be downloaded from the Realm Object Server. |
public synchronized void | Adds a progress listener tracking changes that need to be uploaded from the device to the Realm Object Server. |
public 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. |
public void | Calling this method will block until all known remote changes have been downloaded and applied to the Realm. |
public SyncConfiguration | Returns the SyncConfiguration that is responsible for controlling the session. |
public ConnectionState | Get the current state of the connection used by the session as defined in ConnectionState . |
public URI | getServerUrl () Returns the URI describing the remote Realm which this session connects to and synchronizes changes with. |
public SyncSession.State | getState () Get the current session's state, as defined in SyncSession.State . |
public User | getUser () Returns the User defined by the SyncConfiguration that is used to connect to MongoDB Realm. |
public boolean | isConnected () Checks if the session is connected to the server and can synchronize data. |
public synchronized void | Removes a previously registered ConnectionListener . |
public synchronized void | Removes a progress listener. |
public synchronized void | start () Attempts to start the session and enable synchronization with the Realm Object Server. |
public synchronized void | stop () Stops any synchronization with the Realm Object Server until the Realm is re-opened again after fully closing it. |
public boolean | Calling this method will block until all known local changes have been uploaded to the server or the specified timeout is hit. |
public void | Calling this method will block until all known local changes have been uploaded to the server. |
Inherited Methods
Methods inherited from class java.lang.Object :
getClass
,hashCode
,equals
,clone
,toString
,notify
,notifyAll
,wait
,wait
,wait
,finalize
Method Detail
addConnectionChangeListener
Adds a listener tracking changes to the connection backing this session. See ConnectionState for further details. Parameters
Throws
|
addDownloadProgressListener
Adds a progress listener tracking changes that need to be downloaded from the Realm Object Server.The ProgressListener will be triggered immediately when registered, and periodically afterwards. Parameters
|
addUploadProgressListener
Adds a progress listener tracking changes that need to be uploaded from the device to the Realm Object Server.The ProgressListener will be triggered immediately when registered, and periodically afterwards. Parameters
|
downloadAllServerChanges
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.This method cannot be called before the Realm has been opened. Returns
Throws
|
public void downloadAllServerChanges () |
---|
Calling this method will block until all known remote changes have been downloaded and applied to the Realm. This will involve network access, so calling this method should only be done from a non-UI thread.If the device is offline, this method might never return. This method cannot be called before the session has been started. Throws
|
getConfiguration
public SyncConfiguration getConfiguration () |
---|
Returns the SyncConfiguration that is responsible for controlling the session. Returns SyncConfiguration that defines and controls this session. |
getConnectionState
public ConnectionState getConnectionState () |
---|
Get the current state of the connection used by the session as defined in ConnectionState . Returns the state of connection used by the session. |
getServerUrl
public URI getServerUrl () |
---|
getState
public SyncSession.State getState () |
---|
Get the current session's state, as defined in SyncSession.State . Note that the state may change after this method returns. Returns the state of the session. |
getUser
Returns the User defined by the SyncConfiguration that is used to connect to MongoDB Realm. Returns User used to authenticate the session on MongoDB Realm. |
isConnected
public boolean isConnected () |
---|
Checks if the session is connected to the server and can synchronize data. This is a best guess effort. To conserve battery the underlying implementation uses heartbeats to detect if the connection is still available. So if no data is actively being synced and some time has elapsed since the last heartbeat, the connection could have been dropped but this method will still return Returns
|
removeConnectionChangeListener
Removes a previously registered ConnectionListener . Parameters
Throws
|
removeProgressListener
Removes a progress listener. If the listener wasn't registered, this method will do nothing. Parameters
|
start
public synchronized void start () |
---|
Attempts to start the session and enable synchronization with the Realm Object Server.This happens automatically when opening the Realm instance, so doing it manually should only be needed if the session was stopped using stop() . If the session was already started, calling this method will do nothing. A session is considered started if getState() returns State.ACTIVE . If the session is State.DYING , the session will be moved back to State.ACTIVE . |
stop
uploadAllLocalChanges
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.This method cannot be called before the Realm has been opened. Returns
Throws
|
public void uploadAllLocalChanges () |
---|
Calling this method will block until all known local changes have been uploaded to the server. This will involve network access, so calling this method should only be done from a non-UI thread.If the device is offline, this method might never return. This method cannot be called before the Realm has been opened. Throws
|