Class ConnectionContext

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

public class ConnectionContext extends Object implements AutoCloseable
Author:
Randall Hauch
  • Field Details

    • 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.
    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • config

      protected final Configuration config
    • pool

      protected final MongoClients pool
    • backoffStrategy

      protected final DelayStrategy backoffStrategy
    • useHostsAsSeeds

      protected final boolean useHostsAsSeeds
  • Constructor Details

    • ConnectionContext

      public ConnectionContext(Configuration config)
      Parameters:
      config - the configuration
  • Method Details

    • shutdown

      public void shutdown()
    • close

      public final void close()
      Specified by:
      close in interface AutoCloseable
    • logger

      protected org.slf4j.Logger logger()
    • clients

      public MongoClients clients()
    • performSnapshotEvenIfNotNeeded

      public boolean performSnapshotEvenIfNotNeeded()
    • clientFor

      public com.mongodb.client.MongoClient clientFor(ReplicaSet replicaSet)
    • clientFor

      public com.mongodb.client.MongoClient clientFor(String seedAddresses)
    • clientForSeedConnection

      public com.mongodb.client.MongoClient clientForSeedConnection()
    • clientFor

      public com.mongodb.client.MongoClient clientFor(com.mongodb.ConnectionString connectionString)
    • clientFor

      public com.mongodb.client.MongoClient clientFor(List<com.mongodb.ServerAddress> addresses)
    • hosts

      public String hosts()
    • connectionSeed

      public String connectionSeed()
      Initial connection seed which is either a host specification or connection string
      Returns:
      hosts or connection string
    • maskedConnectionSeed

      public String maskedConnectionSeed()
      Same as connectionSeed() but masks sensitive information
      Returns:
      masked connection seed
    • connectionString

      public Optional<com.mongodb.ConnectionString> connectionString()
    • pollInterval

      public Duration pollInterval()
    • primaryFor

      public ConnectionContext.MongoPrimary primaryFor(ReplicaSet replicaSet, Filters filters, BiConsumer<String,Throwable> errorHandler)
      Obtain a client that will repeatedly try to obtain a client to the primary node of the replica set, waiting (and using this context's back-off strategy) if required until the primary becomes available.
      Parameters:
      replicaSet - the replica set information; may not be null
      filters - the filter configuration
      errorHandler - the function to be called whenever the primary is unable to execute an operation to completion; may be null
      Returns:
      the client, or null if no primary could be found for the replica set
    • preferredFor

      public ConnectionContext.MongoPreferredNode preferredFor(ReplicaSet replicaSet, com.mongodb.ReadPreference preference, Filters filters, BiConsumer<String,Throwable> errorHandler)
      Obtain a client that will repeatedly try to obtain a client to a node of preferred type of the replica set, waiting (and using this context's back-off strategy) if required until the node becomes available.
      Parameters:
      replicaSet - the replica set information; may not be null
      filters - the filter configuration
      errorHandler - the function to be called whenever the node is unable to execute an operation to completion; may be null
      Returns:
      the client, or null if no primary could be found for the replica set
    • preferredClientFor

      protected Supplier<com.mongodb.client.MongoClient> preferredClientFor(ReplicaSet replicaSet, com.mongodb.ReadPreference preference)
      Obtain a client that will repeatedly try to obtain a client to a node of preferred type of the replica set, waiting (and using this context's back-off strategy) if required until the node becomes available.
      Parameters:
      replicaSet - the replica set information; may not be null
      Returns:
      the client, or null if no node of preferred type could be found for the replica set
    • preferredClientFor

      protected Supplier<com.mongodb.client.MongoClient> preferredClientFor(ReplicaSet replicaSet, com.mongodb.ReadPreference preference, ConnectionContext.PreferredConnectFailed handler)
      Obtain a client that will repeated try to obtain a client to the primary node of the replica set, waiting (and using this context's back-off strategy) if required until the primary becomes available.
      Parameters:
      replicaSet - the replica set information; may not be null
      handler - the function that will be called when the primary could not be obtained; may not be null
      Returns:
      the client, or null if no primary could be found for the replica set
    • clientForPreferred

      protected com.mongodb.client.MongoClient clientForPreferred(ReplicaSet replicaSet, com.mongodb.ReadPreference preference)
      Obtain a client that talks only to the primary node of the replica set.
      Parameters:
      replicaSet - the replica set information; may not be null
      Returns:
      the client, or null if no primary could be found for the replica set