Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
io.realm.mongodb.sync

Class SyncSession

java.lang.Object
io.realm.mongodb.sync.SyncSession

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.

Una sesión está controlada por Realm, pero puede proporcionar información adicional en casos de errores. Estos errores se transmiten en el SyncSession.ErrorHandler .

Al crear una sesión, Realm establecerá una conexión con el servidor. Esta conexión está controlada por Realm y puede compartirse entre varias sesiones. Es posible obtener información sobre la conexión mediante addConnectionChangeListener(ConnectionListener) e isConnected().

La sesión en sí tiene un ciclo de vida diferente al de la conexión subyacente. El estado de la sesión se puede consultar mediante getState().

El objeto SyncSession es seguro para subprocesos (thread safe).

Modificador y Tipo
Clase y descripción

public static final

public static interface

public static interface

Modificador y Tipo
Método y descripción

public synchronized void

Adds a listener tracking changes to the connection backing this session.

public synchronized void

Agrega un listener de progreso que rastrea los cambios que deben descargarse desde el servidor de objeto Realm.

public synchronized void

Adds a progress listener tracking changes that need to be uploaded from the device to the Realm Object Server.

public booleano

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

Llamar a este método bloqueará hasta que se hayan descargado y aplicado todos los cambios remotos conocidos al Realm.

Returns the SyncConfiguration that is responsible for controlling the session.

Get the current state of the connection used by the session as defined in ConnectionState .

public URI

Returns the URI describing the remote Realm which this session connects to and synchronizes changes with.

Obtenga el estado de la sesión actual, como se define en SyncSession.State.

public User

Devuelve el usuario definido por SyncConfiguration que se utiliza para conectarse a MongoDB Realm.

public booleano

Checks if the session is connected to the server and can synchronize data.

public synchronized void

Remueve una ConnectionListener previamente registrada.

public synchronized void

Remueve un listener de progreso.

public synchronized void

Intenta iniciar la sesión y habilitar la sincronización con el servidor de objetos Realm.

public synchronized void

stop ()

Stops any synchronization with the Realm Object Server until the Realm is re-opened again after fully closing it.

public booleano

long timeout,
)

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.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

public synchronized void addConnectionChangeListener (
)

Añade un detector que rastrea los cambios en la conexión que respalda esta sesión. Consulta ConnectionState para más detalles.

Parámetros

  • listener - the listener to register.

Throws

Tip

public synchronized void 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.

Parámetros

  • mode - type of mode used. See ProgressMode for more information.

  • listener - the listener to register.

public synchronized void 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.

Parámetros

  • mode - type of mode used. See ProgressMode for more information.

  • listener - the listener to register.

public boolean downloadAllServerChanges (
long timeout,
)

Llamar a este método bloqueará hasta que todos los cambios remotos conocidos hayan sido descargados y aplicados al Realm o hasta que se alcance el tiempo límite especificado. Esto implicará acceso a la red, por lo que llamar a este método solo debe realizarse desde un hilo que no sea de la Interfaz de Usuario. Este método no se puede llamar antes de que el Realm esté abierto.

Devuelve

true if the data was downloaded before the timeout. false if the operation timed out or otherwise failed.

Throws

  • IllegalStateException - if called on the Android main thread.

  • InterruptedException - si la descarga tomó más tiempo que el tiempo de espera especificado o si el hilo se interrumpió mientras la descarga estaba en curso. La descarga continuará en segundo plano incluso después de que se produzca esta excepción.

  • IllegalArgumentException: si timeout es menor o igual que 0 unit o null es.

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

Returns the SyncConfiguration that is responsible for controlling the session.

Devuelve

SyncConfiguration that defines and controls this session.

Get the current state of the connection used by the session as defined in ConnectionState .

Devuelve

el estado de conexión utilizado por la sesión.

public URI getServerUrl ()

Returns the URI describing the remote Realm which this session connects to and synchronizes changes with.

Devuelve

URI describing the remote Realm.

Obtenga el estado de la sesión actual, como se define en SyncSession.State.

Note that the state may change after this method returns.

Devuelve

the state of the session.

public User getUser ()

Devuelve el usuario definido por SyncConfiguration que se utiliza para conectarse a MongoDB Realm.

Devuelve

Usuario utilizado para autenticar la sesión en MongoDB Realm.

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 true .

Devuelve

true si la sesión está conectada y lista para sincronizar datos, false si no lo está o si está en proceso de conexión.

public synchronized void removeConnectionChangeListener (
)

Remueve una ConnectionListener previamente registrada.

Parámetros

  • listener - listener to remove

Throws

public synchronized void removeProgressListener (
)

Removes a progress listener. If the listener wasn't registered, this method will do nothing.

Parámetros

  • listener - listener to remove.

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 .

public synchronized void stop ()

Stops any synchronization with the Realm Object Server until the Realm is re-opened again after fully closing it.Synchronization can be re-enabled by calling start() again.

Si la sesión ya está detenida, llamar a este método no hará nada.

public boolean uploadAllLocalChanges (
long timeout,
)

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.

Devuelve

true if the data was uploaded before the timeout. false if the operation timed out or otherwise failed.

Throws

  • IllegalStateException - if called on the Android main thread.

  • InterruptedException - if the upload took longer than the specified timeout or the thread was interrupted while uploading was in progress. The upload will continue in the background even after this exception is thrown.

  • IllegalArgumentException: si timeout es menor o igual que 0 unit o null es.

public void uploadAllLocalChanges ()

Llamar a este método bloqueará hasta que todos los cambios locales conocidos se hayan subido al servidor. Esto implicará acceso a la red, por lo que solo se debe llamar a este método desde un subproceso que no sea de Interfaz de Usuario. Si el dispositivo está sin conexión, este método podría no devolver nunca una respuesta.

This method cannot be called before the Realm has been opened.

Throws

Volver

SyncConfiguration.InitialFlexibleSyncSubscriptions

En esta página