Class DataSynchronizer

  • All Implemented Interfaces:
    NetworkMonitor.StateListener

    public class DataSynchronizer
    extends Object
    implements NetworkMonitor.StateListener
    DataSynchronizer handles the bidirectional synchronization of documents between a local MongoDB and a remote MongoDB (via Stitch). It also expose CRUD operations to interact with synchronized documents.
    • Method Detail

      • getSyncConfig

        public com.mongodb.stitch.core.services.mongodb.remote.sync.internal.InstanceSynchronizationConfig getSyncConfig()
      • reinitialize

        public void reinitialize​(MongoClient localClient)
      • wipeInMemorySettings

        public void wipeInMemorySettings()
        Reloads the synchronization config. This wipes all in-memory synchronization settings.
      • start

        public void start()
        Starts data synchronization in a background thread.
      • disableSyncThread

        public void disableSyncThread()
      • disableListeners

        public void disableListeners()
      • stop

        public void stop()
        Stops the background data synchronization thread.
      • close

        public void close()
        Stops the background data synchronization thread and releases the local client.
      • doSyncPass

        public boolean doSyncPass()
        Performs a single synchronization pass in both the local and remote directions; the order of which does not matter. If switching the order produces different results after one pass, then there is a bug.
        Returns:
        whether or not the synchronization pass was successful.
      • getSynchronizedNamespaces

        public Set<MongoNamespace> getSynchronizedNamespaces()
        Returns the set of synchronized namespaces.
        Returns:
        the set of synchronized namespaces.
      • getSynchronizedDocuments

        public Set<CoreDocumentSynchronizationConfig> getSynchronizedDocuments​(MongoNamespace namespace)
        Returns the set of synchronized documents in a namespace.
        Parameters:
        namespace - the namespace to get synchronized documents for.
        Returns:
        the set of synchronized documents in a namespace.
      • getPausedDocumentIds

        public Set<BsonValue> getPausedDocumentIds​(MongoNamespace namespace)
        Return the set of synchronized document _ids in a namespace that have been paused due to an irrecoverable error.
        Parameters:
        namespace - the namespace to get paused document _ids for.
        Returns:
        the set of paused document _ids in a namespace
      • syncDocumentsFromRemote

        public void syncDocumentsFromRemote​(MongoNamespace namespace,
                                            BsonValue... documentIds)
        Requests that a document be synchronized by the given _id. Actual synchronization of the document will happen later in a doSyncPass() iteration.
        Parameters:
        namespace - the namespace to put the document in.
        documentIds - the _ids of the documents.
      • isRunning

        public boolean isRunning()
        Whether or not the DataSynchronizer is running in the background.
        Returns:
        true if running, false if not
      • areAllStreamsOpen

        public boolean areAllStreamsOpen()