public class SyncSession extends Object
SyncConfiguration
.
A Session is created by opening a Realm instance using that configuration. 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 fully controlled by Realm, but can provide additional information in case of errors.
It is passed along in all SyncSession.ErrorHandler
s.
This object is thread safe.
Modifier and Type | Class and Description |
---|---|
static interface |
SyncSession.ErrorHandler
Interface used to report any session errors.
|
static class |
SyncSession.State |
Modifier and Type | Method and Description |
---|---|
void |
addDownloadProgressListener(ProgressMode mode,
ProgressListener listener)
Adds a progress listener tracking changes that need to be downloaded from the Realm Object
Server.
|
void |
addUploadProgressListener(ProgressMode mode,
ProgressListener listener)
Adds a progress listener tracking changes that need to be uploaded from the device to the
Realm Object Server.
|
void |
downloadAllServerChanges()
Calling this method will block until all known remote changes have been downloaded and applied to the Realm.
|
SyncConfiguration |
getConfiguration()
Returns the
SyncConfiguration that is responsible for controlling the session. |
URI |
getServerUrl()
Returns the
URI describing the remote Realm which this session connects to and synchronizes changes with. |
SyncSession.State |
getState()
Get the current session's state, as defined in
SyncSession.State . |
SyncUser |
getUser()
Returns the
SyncUser defined by the SyncConfiguration that is used to connect to the
Realm Object Server. |
void |
removeProgressListener(ProgressListener listener)
Removes a progress listener.
|
void |
setResolvedRealmURI(URI resolvedRealmURI) |
void |
uploadAllLocalChanges()
Calling this method will block until all known local changes have been uploaded to the server.
|
public SyncConfiguration getConfiguration()
SyncConfiguration
that is responsible for controlling the session.public SyncUser getUser()
SyncUser
defined by the SyncConfiguration
that is used to connect to the
Realm Object Server.SyncUser
used to authenticate the session on the Realm Object Server.public URI getServerUrl()
URI
describing the remote Realm which this session connects to and synchronizes changes with.URI
describing the remote Realm.public SyncSession.State getState()
SyncSession.State
.
Note that the state may change after this method returns, example: the authentication
token will expire, causing the session to move to SyncSession.State.WAITING_FOR_ACCESS_TOKEN
after it was in SyncSession.State.ACTIVE
.SyncSession.State
public void addDownloadProgressListener(ProgressMode mode, ProgressListener listener)
The ProgressListener
will be triggered immediately when registered, and periodically
afterwards.
mode
- type of mode used. See ProgressMode
for more information.listener
- the listener to register.public void addUploadProgressListener(ProgressMode mode, ProgressListener listener)
The ProgressListener
will be triggered immediately when registered, and periodically
afterwards.
mode
- type of mode used. See ProgressMode
for more information.listener
- the listener to register.public void removeProgressListener(ProgressListener listener)
listener
- listener to remove.public void downloadAllServerChanges() throws InterruptedException
If the device is offline, this method might never return.
This method cannot be called before the session has been started.
IllegalStateException
- if called on the Android main thread.InterruptedException
- if the thread was interrupted while downloading was in progress.public void uploadAllLocalChanges() throws InterruptedException
If the device is offline, this method might never return.
This method cannot be called before the session has been started.
IllegalStateException
- if called on the Android main thread.InterruptedException
- if the thread was interrupted while downloading was in progress.public void setResolvedRealmURI(URI resolvedRealmURI)