Package io.debezium.connector.mongodb
Class ConnectionContext.MongoPrimary
java.lang.Object
io.debezium.connector.mongodb.ConnectionContext.MongoPrimary
- Enclosing class:
- ConnectionContext
A supplier of a client that connects only to the primary of a replica set. Operations on the primary will continue
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BiConsumer<String,Throwable> private final Filtersprivate final Supplier<com.mongodb.client.MongoClient>private final ReplicaSetprivate final AtomicBoolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMongoPrimary(ConnectionContext context, ReplicaSet replicaSet, Filters filters, BiConsumer<String, Throwable> errorHandler) -
Method Summary
Modifier and TypeMethodDescriptioncom.mongodb.ServerAddressaddress()Get the address of the primary node, if there is one.Use the primary to get the identifiers of all the collections in the replica set, applying the current collection filter configuration.Use the primary to get the names of all the databases in the replica set, applying the current database filter configuration.voidExecute the supplied operation using the primary, blocking until a primary is available.<T> TExecute the supplied operation using the primary, blocking until a primary is available.voidexecuteBlocking(String desc, BlockingConsumer<com.mongodb.client.MongoClient> operation) Execute the supplied operation using the primary, blocking until a primary is available.private booleanGet the replica set.voidstop()Terminates the execution loop of the current primary
-
Field Details
-
replicaSet
-
-
filters
-
errorHandler
-
running
-
-
Constructor Details
-
MongoPrimary
protected MongoPrimary(ConnectionContext context, ReplicaSet replicaSet, Filters filters, BiConsumer<String, Throwable> errorHandler)
-
-
Method Details
-
replicaSet
Get the replica set.- Returns:
- the replica set; never null
-
address
public com.mongodb.ServerAddress address()Get the address of the primary node, if there is one.- Returns:
- the address of the replica set's primary node, or
nullif there is currently no primary
-
execute
Execute the supplied operation using the primary, blocking until a primary is available. Whenever the operation stops (e.g., if the primary is no longer primary), then restart the operation using the current primary.- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed on the primary.
-
execute
Execute the supplied operation using the primary, blocking until a primary is available. Whenever the operation stops (e.g., if the primary is no longer primary), then restart the operation using the current primary.- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed on the primary- Returns:
- return value of the executed operation
-
executeBlocking
public void executeBlocking(String desc, BlockingConsumer<com.mongodb.client.MongoClient> operation) throws InterruptedException Execute the supplied operation using the primary, blocking until a primary is available. Whenever the operation stops (e.g., if the primary is no longer primary), then restart the operation using the current primary.- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed on the primary.- Throws:
InterruptedException- if the operation was interrupted
-
databaseNames
Use the primary to get the names of all the databases in the replica set, applying the current database filter configuration. This method will block until a primary can be obtained to get the names of all databases in the replica set.- Returns:
- the database names; never null but possibly empty
-
collections
Use the primary to get the identifiers of all the collections in the replica set, applying the current collection filter configuration. This method will block until a primary can be obtained to get the identifiers of all collections in the replica set.- Returns:
- the collection identifiers; never null
-
isRunning
private boolean isRunning() -
stop
public void stop()Terminates the execution loop of the current primary
-