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 Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate final MongoDbConnectionContextprivate final MongoDbConnectorConfigprivate final MongoDbConnection.ErrorHandlerprivate final Filtersstatic final org.slf4j.Loggerprivate static final DurationA pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database.private final AtomicBoolean -
Constructor Summary
ConstructorsConstructorDescriptionMongoDbConnection(Configuration config, 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.com.mongodb.client.MongoClientorg.bson.BsonTimestamphello()Executes the ping command (Ping) using the first available databaseprivate booleanprivate booleanisValidResumeToken(org.bson.BsonDocument token, MongoDbTaskContext taskContext) booleanvalidateLogPosition(MongoDbOffsetContext offset, MongoDbTaskContext taskContext)
-
Field Details
-
LOGGER
public static final org.slf4j.Logger LOGGER -
AUTHORIZATION_FAILURE_MESSAGE
- See Also:
-
PAUSE_AFTER_ERROR
A pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database. -
filters
-
errorHandler
-
running
-
connectorConfig
-
connectionContext
-
-
Constructor Details
-
MongoDbConnection
MongoDbConnection(Configuration config, MongoDbConnection.ErrorHandler errorHandler)
-
-
Method Details
-
getMongoClient
public com.mongodb.client.MongoClient getMongoClient() -
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
-
hello
Executes the ping command (Ping) using the first available database- Returns:
- timestamp of the executed operation
- Throws:
InterruptedException
-
isRunning
private boolean isRunning() -
validateLogPosition
-
isValidResumeToken
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-