Class ConnectionContext.MongoPreferredNode

java.lang.Object
io.debezium.connector.mongodb.ConnectionContext.MongoPreferredNode
Direct Known Subclasses:
ConnectionContext.MongoPrimary
Enclosing class:
ConnectionContext

public static class ConnectionContext.MongoPreferredNode extends Object
A supplier of a client that connects only to node of preferred type from a replica set. Operations on this node will continue
  • Field Details

    • replicaSet

      private final ReplicaSet replicaSet
    • connectionSupplier

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

      private final Filters filters
    • errorHandler

      private final BiConsumer<String,Throwable> errorHandler
    • running

      private final AtomicBoolean running
    • preference

      private final com.mongodb.ReadPreference preference
  • Constructor Details

  • Method Details

    • replicaSet

      public ReplicaSet 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 null if there is currently no node of preferred type
    • execute

      public void execute(String desc, Consumer<com.mongodb.client.MongoClient> operation)
      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 purposes
      operation - the operation to be performed on a node of preferred type.
    • execute

      public <T> T execute(String desc, Function<com.mongodb.client.MongoClient,T> operation)
      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 purposes
      operation - 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 purposes
      operation - the operation to be performed on a node of preferred type.
      Throws:
      InterruptedException - if the operation was interrupted
    • databaseNames

      public Set<String> 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

      public List<CollectionId> 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