Class MongoDbConnection
java.lang.Object
io.debezium.connector.mongodb.connection.MongoDbConnection
- All Implemented Interfaces:
AutoCloseable
Scoped Mongodb Connection which applies filter configuration and replica set specification when required
Internally this wrapper attempts to obtain regular
MongoClient instance-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate final Supplier<com.mongodb.client.MongoClient>private final MongoDbConnection.ErrorHandlerprivate final Filtersprivate final Stringprivate static final DurationA pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database.private final AtomicBoolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMongoDbConnection(com.mongodb.ConnectionString connectionString, MongoDbClientFactory clientFactory, Filters filters) protectedMongoDbConnection(ReplicaSet replicaSet, com.mongodb.ReadPreference readPreference, MongoDbClientFactory clientFactory, Filters filters, MongoDbConnection.ErrorHandler errorHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Get the identifiers of all the collections, applying the current collection filter configuration.Get the names of all the databases applying the current database filter configuration.voidexecute(String desc, BlockingConsumer<com.mongodb.client.MongoClient> operation) Execute the supplied operation.<T> Texecute(String desc, BlockingFunction<com.mongodb.client.MongoClient, T> operation) Execute the supplied operation.private boolean
-
Field Details
-
AUTHORIZATION_FAILURE_MESSAGE
- See Also:
-
PAUSE_AFTER_ERROR
A pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database. -
DEFAULT_ERROR_HANDLER
-
filters
-
errorHandler
-
running
-
name
-
connectionSupplier
-
-
Constructor Details
-
MongoDbConnection
protected MongoDbConnection(ReplicaSet replicaSet, com.mongodb.ReadPreference readPreference, MongoDbClientFactory clientFactory, Filters filters, MongoDbConnection.ErrorHandler errorHandler) -
MongoDbConnection
protected MongoDbConnection(com.mongodb.ConnectionString connectionString, MongoDbClientFactory clientFactory, Filters filters)
-
-
Method Details
-
execute
public void execute(String desc, BlockingConsumer<com.mongodb.client.MongoClient> operation) throws InterruptedException Execute the supplied operation. Whenever the operation fails the error handler is called and the operation is repeated- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed- Throws:
InterruptedException
-
execute
public <T> T execute(String desc, BlockingFunction<com.mongodb.client.MongoClient, T> operation) throws InterruptedExceptionExecute the supplied operation. Whenever the operation fails the error handler is called and the operation is repeated- Parameters:
desc- the description of the operation, for logging purposesoperation- the operation to be performed- Returns:
- return value of the executed operation
- Throws:
InterruptedException
-
databaseNames
Get the names of all the databases applying the current database filter configuration.- Returns:
- the database names; never null but possibly empty
- Throws:
InterruptedException
-
collections
Get the identifiers of all the collections, applying the current collection filter configuration.- Returns:
- the collection identifiers; never null
- Throws:
InterruptedException
-
isRunning
private boolean isRunning() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-