public class SyncManager extends Object
SyncSession
s and it is possible to configure session defaults and the underlying
network client using this class.
Through the SyncManager, it is possible to add authentication listeners. An authentication listener will response to events like user logging in or out.
Default error handling for any SyncConfiguration
can be added using the SyncManager.
Modifier and Type | Class and Description |
---|---|
static class |
SyncManager.Debug
Debugging related options.
|
Modifier and Type | Field and Description |
---|---|
static String |
APP_ID
APP ID sent to the Realm Object Server.
|
static ThreadPoolExecutor |
NETWORK_POOL_EXECUTOR
Thread pool used when doing network requests against the Realm Object Server.
|
Constructor and Description |
---|
SyncManager() |
Modifier and Type | Method and Description |
---|---|
static void |
addAuthenticationListener(AuthenticationListener listener)
Sets a global authentication listener that will be notified about User events like
login and logout.
|
static SyncSession |
getOrCreateSession(SyncConfiguration syncConfiguration,
URI resolvedRealmURL)
Gets any cached
SyncSession for the given SyncConfiguration or create a new one if
no one exists. |
static SyncSession |
getSession(SyncConfiguration syncConfiguration)
Gets a cached
SyncSession for the given SyncConfiguration or throw if no one exists yet. |
static UserStore |
getUserStore() |
static void |
removeAuthenticationListener(AuthenticationListener listener)
Removes the provided global authentication listener.
|
static void |
setDefaultSessionErrorHandler(SyncSession.ErrorHandler errorHandler)
Sets the default error handler used by all
SyncConfiguration objects when they are created. |
static void |
setUserStore(UserStore userStore)
Set the
UserStore used by the Realm Object Server to save user information. |
public static String APP_ID
public static ThreadPoolExecutor NETWORK_POOL_EXECUTOR
This pool is only exposed for testing purposes and replacing it while the queue is not empty will result in undefined behaviour.
public static void setUserStore(UserStore userStore)
UserStore
used by the Realm Object Server to save user information.
If no Userstore is specified SyncUser.current()
will always return null
.userStore
- UserStore
to use.IllegalArgumentException
- if userStore
is null
.public static void addAuthenticationListener(AuthenticationListener listener)
listener
- listener to register.IllegalArgumentException
- if listener
is null
.public static void removeAuthenticationListener(AuthenticationListener listener)
listener
- listener to remove.public static void setDefaultSessionErrorHandler(SyncSession.ErrorHandler errorHandler)
SyncConfiguration
objects when they are created.errorHandler
- the default error handler used when interacting with a Realm managed by a Realm Object Server.public static SyncSession getSession(SyncConfiguration syncConfiguration) throws IllegalStateException
SyncSession
for the given SyncConfiguration
or throw if no one exists yet.
A session should exist after you open a Realm with a SyncConfiguration
.syncConfiguration
- configuration object for the synchronized Realm.SyncSession
for the specified Realm.IllegalArgumentException
- if syncConfiguration is null
.IllegalStateException
- if the session could not be found using the provided SyncConfiguration
.public static SyncSession getOrCreateSession(SyncConfiguration syncConfiguration, URI resolvedRealmURL)
SyncSession
for the given SyncConfiguration
or create a new one if
no one exists.
Note: This is mainly for internal usage, consider using getSession(SyncConfiguration)
instead.syncConfiguration
- configuration object for the synchronized Realm.resolvedRealmURL
- resolved Realm URL with the user specific part if not a global Realm.SyncSession
for the specified Realm.IllegalArgumentException
- if syncConfiguration is null
.public static UserStore getUserStore()