Package com.couchbase.lite
Class MultipeerReplicator
java.lang.Object
com.couchbase.lite.MultipeerReplicator
- All Implemented Interfaces:
AutoCloseable
The MultipeerReplicator replicates database collections between devices using
the Multipeer Connectivity framework. It provides peer discovery, connection management,
and data replication.
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes the MultipeerReplicator with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionAdds a listener to receive updates on the peer discovery status.addPeerDiscoveryStatusListener(Executor executor, PeerDiscoveryStatus.Listener listener) Adds a listener to receive updates on the peer discovery status.Adds a listener to receive updates on the document replication status for each connected peer.addPeerDocumentReplicationListener(Executor executor, PeerDocumentReplication.Listener listener) Adds a listener to receive updates on the document replication status for each connected peer.Adds a listener to receive updates on the replicator status for each connected peer.addPeerReplicatorStatusListener(Executor executor, PeerReplicatorStatus.Listener listener) Adds a listener to receive updates on the replicator status for each connected peer.Adds a listener to receive updates on the multipeer replicator status.addStatusListener(Executor executor, MultipeerReplicatorStatus.Listener listener) Adds a listener to receive updates on the multipeer replicator status.voidclose()Immediately release the native replicator and all its resources.The configuration.getMissingPermissions(android.content.Context context) Return set of missing (not granted) permissions.Returns the set of necessary permissions required by the application.Returns the set of peer IDs currently online.The peer ID of this replicator.getPeerInfo(PeerInfo.PeerId peerId) Returns information about the peer with the given ID, ornullif no such peer is known.getStatus(MultipeerTransport transport) Returns the current status of this replicator for the given transport, ornullif the transport is not configured.voidstart()Starts peer discovery and initiates replication with connected peers.voidstop()Stops peer discovery and all replicators.
-
Constructor Details
-
MultipeerReplicator
public MultipeerReplicator(@NonNull MultipeerReplicatorConfiguration config) throws CouchbaseLiteException Initializes the MultipeerReplicator with the given configuration.- Parameters:
config- The configuration for the replicator.- Throws:
CouchbaseLiteException- on error creating the replicator.
-
-
Method Details
-
getConfig
The configuration.- Returns:
- The configuration.
-
getPeerId
The peer ID of this replicator.- Returns:
- the peer ID of this replicator.
-
getStatus
Returns the current status of this replicator for the given transport, ornullif 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
nullif the transport is not configured for this replicator.
-
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 viaclose()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. Afterclose(), any further operation on this replicator throwsCouchbaseLiteError.- Specified by:
closein interfaceAutoCloseable
-
getPeerInfo
Returns information about the peer with the given ID, ornullif 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
nullif no peer with that ID is known.
-
getNecessaryPermissions
Returns the set of necessary permissions required by the application.- Returns:
- A set of necessary permissions (Strings).
-
getMissingPermissions
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.
-