Class SyncBuilder

java.lang.Object
io.objectbox.sync.SyncBuilder

public final class SyncBuilder extends Object
A builder to create a SyncClient; the builder itself should be created via Sync.client(BoxStore).
  • Method Details

    • url

      public SyncBuilder url(String url)
      Adds a Sync server URL the client should connect to.

      This is typically a WebSockets URL starting with ws:// or wss:// (for encrypted connections), for example if the server is running on localhost ws://127.0.0.1:9999.

      Can be called multiple times to add multiple URLs for high availability and load balancing (like when using an ObjectBox Sync Server Cluster). A random URL is selected for each connection attempt.

      Parameters:
      url - The URL of the Sync server on which the Sync protocol is exposed.
      Returns:
      this builder for chaining
      See Also:
    • urls

      public SyncBuilder urls(List<String> urls)
      Like url(String), but accepts a list of URLs.
      Parameters:
      urls - A list of URLs of Sync servers on which the Sync protocol is exposed.
      Returns:
      this builder for chaining
      See Also:
    • credentials

      public SyncBuilder credentials(SyncCredentials credentials)
      Adds SyncCredentials to authenticate the client with the server.

      The accepted credentials types depend on your Sync server configuration.

      Parameters:
      credentials - credentials created using a SyncCredentials factory method, for example SyncCredentials.jwtIdToken(idToken).
      See Also:
    • credentials

      public SyncBuilder credentials(List<SyncCredentials> credentials)
      Like credentials(SyncCredentials), but accepts a list of credentials.
      Parameters:
      credentials - a list of credentials where each element is created using a SyncCredentials factory method, for example SyncCredentials.jwtIdToken(idToken).
      Returns:
      this builder for chaining
    • filterVariable

      public SyncBuilder filterVariable(String name, String value)
      Adds or replaces a Sync filter variable value for the given name.

      Sync client filter variables can be used in server-side Sync filters to filter out objects that do not match the filter.

      See Also:
    • trustedCertificates

      public SyncBuilder trustedCertificates(String[] paths)
      Configures a custom set of directory or file paths to search for trusted certificates in. The first path that exists will be used.

      Using this option is not recommended in most cases, as by default the sync client uses the certificate authorities trusted by the host platform.

    • flags

      public SyncBuilder flags(int flags)
      Sets bit flags to adjust Sync behavior, like additional logging.
      Parameters:
      flags - One or multiple SyncFlags, combined with bitwise or.
    • requestUpdatesMode

      public SyncBuilder requestUpdatesMode(SyncBuilder.RequestUpdatesMode requestUpdatesMode)
      Configure automatic sync updates from the server. If automatic sync updates are turned off, they will need to be requested using the sync client.
      See Also:
    • uncommittedAcks

      public SyncBuilder uncommittedAcks()
      Turns on sending of uncommitted acks.
    • loginListener

      public SyncBuilder loginListener(SyncLoginListener loginListener)
      Sets a listener to only observe Sync login events.

      This listener can also be set or removed on the Sync client directly.

    • completedListener

      public SyncBuilder completedListener(SyncCompletedListener completedListener)
      Sets a listener to only observe Sync completed events.

      This listener can also be set or removed on the Sync client directly.

    • changeListener

      public SyncBuilder changeListener(SyncChangeListener changeListener)
      Sets a listener to observe fine granular changes happening during sync.

      This listener can also be set or removed on the Sync client directly.

    • timeListener

      public SyncBuilder timeListener(SyncTimeListener timeListener)
      Sets a listener to only observe Sync time events.

      This listener can also be set or removed on the Sync client directly.

    • connectionListener

      public SyncBuilder connectionListener(SyncConnectionListener connectionListener)
      Sets a listener to only observe Sync connection events.

      This listener can also be set or removed on the Sync client directly.

    • listener

      public SyncBuilder listener(SyncListener listener)
      Sets a listener to observe all Sync events like login or sync completion.

      Note: this will replace any login, completed or connection listener.

      This listener can also be set or removed on the Sync client directly.

    • build

      public SyncClient build()
      Builds and returns a Sync client ready to SyncClient.start().
    • buildAndStart

      public SyncClient buildAndStart()
      Builds, starts and returns a Sync client.