Package io.debezium.connector.mongodb
Class ConnectionContext.MongoPreferredNode
java.lang.Object
io.debezium.connector.mongodb.ConnectionContext.MongoPreferredNode
- Direct Known Subclasses:
ConnectionContext.MongoPrimary
- Enclosing class:
- ConnectionContext
A supplier of a client that connects only to node of preferred type from a replica set. Operations on this node will continue
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Supplier<com.mongodb.client.MongoClient>private final BiConsumer<String,Throwable> private final Filtersprivate final com.mongodb.ReadPreferenceprivate final ReplicaSetprivate final AtomicBoolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMongoPreferredNode(ConnectionContext context, ReplicaSet replicaSet, com.mongodb.ReadPreference preference, Filters filters, BiConsumer<String, Throwable> errorHandler) -
Method Summary
Modifier and TypeMethodDescriptioncom.mongodb.ServerAddressaddress()Get the address of the node with preferred type, if there is one.Use a node of preferred type to get the identifiers of all the collections in the replica set, applying the current collection filter configuration.Use a node of preferred type to get the names of all the databases in the replica set, applying the current database filter configuration.voidExecute the supplied operation using the preferred node, blocking until it is available.<T> TExecute the supplied operation using the preferred node, blocking until it is available.voidexecuteBlocking(String desc, BlockingConsumer<com.mongodb.client.MongoClient> operation) Execute the supplied operation using the preferred node, blocking until it is available.com.mongodb.ReadPreferenceGet read preference ofprivate booleanGet the replica set.voidstop()Terminates the execution loop of the current primary
-
Field Details
-
replicaSet
-
connectionSupplier
-
filters
-
errorHandler
-
running
-
preference
private final com.mongodb.ReadPreference preference
-
-
Constructor Details
-
MongoPreferredNode
protected MongoPreferredNode(ConnectionContext context, ReplicaSet replicaSet, com.mongodb.ReadPreference preference, Filters filters, BiConsumer<String, Throwable> errorHandler)
-
-
Method Details
-
replicaSet
Get the replica set.- Returns:
- the replica set; never null
-
getPreference
public com.mongodb.ReadPreference getPreference()Get read preference of- Returns:
- the read preference
-
address
public com.mongodb.ServerAddress address()Get the address of the node with preferred type, if there is one.- Returns:
- the address of the replica set's preferred node, or
nullif there is currently no node of preferred type
-
execute
Execute the supplied operation using the preferred node, blocking until it is available. Whenever the operation stops (e.g., if the node is no longer of preferred type), then restart the operation using a current node of that type.- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed on a node of preferred type.
-
execute
Execute the supplied operation using the preferred node, blocking until it is available. Whenever the operation stops (e.g., if the node is no longer of preferred type), then restart the operation using a current node of that type.- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed on a node of preferred type- 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 preferred node, blocking until it is available. Whenever the operation stops (e.g., if the node is no longer of preferred type), then restart the operation using a current node of that type.- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed on a node of preferred type.- Throws:
InterruptedException- if the operation was interrupted
-
databaseNames
Use a node of preferred type to get the names of all the databases in the replica set, applying the current database filter configuration. This method will block until a node of preferred type 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 a node of preferred type 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
-