Class MongoDbConnection

java.lang.Object
io.debezium.connector.mongodb.connection.MongoDbConnection
All Implemented Interfaces:
AutoCloseable

public final class MongoDbConnection extends Object implements AutoCloseable
Scoped Mongodb Connection which applies filter configuration and replica set specification when required Internally this wrapper attempts to obtain regular MongoClient instance
  • Field Details

    • AUTHORIZATION_FAILURE_MESSAGE

      public static final String AUTHORIZATION_FAILURE_MESSAGE
      See Also:
    • PAUSE_AFTER_ERROR

      private static final Duration PAUSE_AFTER_ERROR
      A pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database.
    • DEFAULT_ERROR_HANDLER

      public static MongoDbConnection.ErrorHandler DEFAULT_ERROR_HANDLER
    • filters

      private final Filters filters
    • errorHandler

      private final MongoDbConnection.ErrorHandler errorHandler
    • running

      private final AtomicBoolean running
    • name

      private final String name
    • connectionSupplier

      private final Supplier<com.mongodb.client.MongoClient> connectionSupplier
  • Constructor Details

  • 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 purposes
      operation - the operation to be performed
      Throws:
      InterruptedException
    • execute

      public <T> T execute(String desc, BlockingFunction<com.mongodb.client.MongoClient,T> 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 purposes
      operation - the operation to be performed
      Returns:
      return value of the executed operation
      Throws:
      InterruptedException
    • databaseNames

      public Set<String> databaseNames() throws InterruptedException
      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

      public List<CollectionId> collections() throws InterruptedException
      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:
      close in interface AutoCloseable