Class MultipeerReplicator

java.lang.Object
com.couchbase.lite.MultipeerReplicator
All Implemented Interfaces:
AutoCloseable

public final class MultipeerReplicator extends Object implements AutoCloseable
The MultipeerReplicator replicates database collections between devices using the Multipeer Connectivity framework. It provides peer discovery, connection management, and data replication.
  • Constructor Details

  • Method Details

    • getConfig

      @NonNull public MultipeerReplicatorConfiguration getConfig()
      The configuration.
      Returns:
      The configuration.
    • getPeerId

      @NonNull public PeerInfo.PeerId getPeerId()
      The peer ID of this replicator.
      Returns:
      the peer ID of this replicator.
    • getStatus

      @Nullable public MultipeerReplicatorStatus getStatus(@NonNull MultipeerTransport transport)
      Returns the current status of this replicator for the given transport, or null if the transport is not configured.

      Warning: This method can block for several seconds in some cases. It is recommended to not call this on the UI thread. This is a known issue we plan to address in a future release.

      Parameters:
      transport - The transport whose status is being queried.
      Returns:
      The status for the given transport, or null if the transport is not configured for this replicator.
    • getNeighborPeers

      @NonNull public Set<PeerInfo.PeerId> getNeighborPeers()
      Returns the set of peer IDs currently online.

      Warning: This method can block for several seconds in some cases. It is recommended to not call this on the UI thread. This is a known issue we plan to address in a future release.

      Returns:
      the set of peer IDs currently online; empty if none.
    • start

      public void start()
      Starts peer discovery and initiates replication with connected peers.
    • stop

      public void stop()
      Stops peer discovery and all replicators. Native resources are released later — either via close() or when the object is garbage-collected.
    • close

      public void close()
      Immediately release the native replicator and all its resources. If the replicator is still running this method makes a best-effort attempt to stop. After close(), any further operation on this replicator throws CouchbaseLiteError.
      Specified by:
      close in interface AutoCloseable
    • getPeerInfo

      @Nullable public PeerInfo getPeerInfo(@NonNull PeerInfo.PeerId peerId)
      Returns information about the peer with the given ID, or null if no such peer is known.

      Warning: This method can block for several seconds in some cases. It is recommended to not call this on the UI thread. This is a known issue we plan to address in a future release.

      Parameters:
      peerId - The ID of the peer.
      Returns:
      The peer's info, or null if no peer with that ID is known.
    • getNecessaryPermissions

      @NonNull public Set<String> getNecessaryPermissions()
      Returns the set of necessary permissions required by the application.
      Returns:
      A set of necessary permissions (Strings).
    • getMissingPermissions

      @NonNull public Set<String> getMissingPermissions(@NonNull android.content.Context context)
      Return set of missing (not granted) permissions.
      Parameters:
      context - Application context
    • addStatusListener

      @NonNull public ListenerToken addStatusListener(@NonNull MultipeerReplicatorStatus.Listener listener)
      Adds a listener to receive updates on the multipeer replicator status.
      Parameters:
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addStatusListener

      @NonNull public ListenerToken addStatusListener(@Nullable Executor executor, @NonNull MultipeerReplicatorStatus.Listener listener)
      Adds a listener to receive updates on the multipeer replicator status.
      Parameters:
      executor - The executor to run the listener on.
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addPeerDiscoveryStatusListener

      @NonNull public ListenerToken addPeerDiscoveryStatusListener(@NonNull PeerDiscoveryStatus.Listener listener)
      Adds a listener to receive updates on the peer discovery status.
      Parameters:
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addPeerDiscoveryStatusListener

      @NonNull public ListenerToken addPeerDiscoveryStatusListener(@Nullable Executor executor, @NonNull PeerDiscoveryStatus.Listener listener)
      Adds a listener to receive updates on the peer discovery status.
      Parameters:
      executor - The executor to run the listener on.
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addPeerReplicatorStatusListener

      @NonNull public ListenerToken addPeerReplicatorStatusListener(@NonNull PeerReplicatorStatus.Listener listener)
      Adds a listener to receive updates on the replicator status for each connected peer.
      Parameters:
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addPeerReplicatorStatusListener

      @NonNull public ListenerToken addPeerReplicatorStatusListener(@Nullable Executor executor, @NonNull PeerReplicatorStatus.Listener listener)
      Adds a listener to receive updates on the replicator status for each connected peer.
      Parameters:
      executor - The executor to run the listener on.
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addPeerDocumentReplicationListener

      @NonNull public ListenerToken addPeerDocumentReplicationListener(@NonNull PeerDocumentReplication.Listener listener)
      Adds a listener to receive updates on the document replication status for each connected peer.
      Parameters:
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.
    • addPeerDocumentReplicationListener

      @NonNull public ListenerToken addPeerDocumentReplicationListener(@Nullable Executor executor, @NonNull PeerDocumentReplication.Listener listener)
      Adds a listener to receive updates on the document replication status for each connected peer.
      Parameters:
      executor - The executor to run the listener on.
      listener - The listener to be added.
      Returns:
      A ListenerToken that can be used to remove the listener.