Package io.debezium.connector.mongodb
Class ConnectionContext
- java.lang.Object
-
- io.debezium.connector.mongodb.ConnectionContext
-
- All Implemented Interfaces:
AutoCloseable
public class ConnectionContext extends Object implements AutoCloseable
- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConnectionContext.MongoPrimaryA supplier of a client that connects only to the primary of a replica set.static interfaceConnectionContext.PrimaryConnectFailed
-
Field Summary
Fields Modifier and Type Field Description protected Configurationconfigprivate static org.slf4j.LoggerLOGGERprivate static DurationPAUSE_AFTER_ERRORA pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database.protected MongoClientspoolprotected DelayStrategyprimaryBackoffStrategyprotected ReplicaSetsreplicaSetsprotected booleanuseHostsAsSeeds
-
Constructor Summary
Constructors Constructor Description ConnectionContext(Configuration config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.mongodb.client.MongoClientclientFor(String seedAddresses)com.mongodb.client.MongoClientclientFor(List<com.mongodb.ServerAddress> addresses)protected com.mongodb.client.MongoClientclientForPrimary(ReplicaSet replicaSet)Obtain a client that talks only to the primary node of the replica set.com.mongodb.client.MongoClientclientForReplicaSet(ReplicaSet replicaSet)MongoClientsclients()voidclose()Stringhosts()protected org.slf4j.Loggerlogger()intmaxConnectionAttemptsForPrimary()booleanperformSnapshotEvenIfNotNeeded()DurationpollInterval()protected Supplier<com.mongodb.client.MongoClient>primaryClientFor(ReplicaSet replicaSet)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.protected Supplier<com.mongodb.client.MongoClient>primaryClientFor(ReplicaSet replicaSet, ConnectionContext.PrimaryConnectFailed 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.ConnectionContext.MongoPrimaryprimaryFor(ReplicaSet replicaSet, Filters filters, BiConsumer<String,Throwable> errorHandler)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.ReplicaSetsreplicaSets()voidshutdown()
-
-
-
Field Detail
-
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
-
replicaSets
protected final ReplicaSets replicaSets
-
primaryBackoffStrategy
protected final DelayStrategy primaryBackoffStrategy
-
useHostsAsSeeds
protected final boolean useHostsAsSeeds
-
-
Constructor Detail
-
ConnectionContext
public ConnectionContext(Configuration config)
- Parameters:
config- the configuration
-
-
Method Detail
-
shutdown
public void shutdown()
-
close
public final void close()
- Specified by:
closein interfaceAutoCloseable
-
logger
protected org.slf4j.Logger logger()
-
clients
public MongoClients clients()
-
replicaSets
public ReplicaSets replicaSets()
-
performSnapshotEvenIfNotNeeded
public boolean performSnapshotEvenIfNotNeeded()
-
clientForReplicaSet
public com.mongodb.client.MongoClient clientForReplicaSet(ReplicaSet replicaSet)
-
clientFor
public com.mongodb.client.MongoClient clientFor(String seedAddresses)
-
clientFor
public com.mongodb.client.MongoClient clientFor(List<com.mongodb.ServerAddress> addresses)
-
hosts
public String hosts()
-
pollInterval
public Duration pollInterval()
-
maxConnectionAttemptsForPrimary
public int maxConnectionAttemptsForPrimary()
-
primaryFor
public ConnectionContext.MongoPrimary primaryFor(ReplicaSet replicaSet, Filters filters, BiConsumer<String,Throwable> errorHandler)
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 nullfilters- the filter configurationerrorHandler- the function to be called whenever the primary is unable toexecutean operation to completion; may be null- Returns:
- the client, or
nullif no primary could be found for the replica set
-
primaryClientFor
protected Supplier<com.mongodb.client.MongoClient> primaryClientFor(ReplicaSet replicaSet)
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- Returns:
- the client, or
nullif no primary could be found for the replica set
-
primaryClientFor
protected Supplier<com.mongodb.client.MongoClient> primaryClientFor(ReplicaSet replicaSet, ConnectionContext.PrimaryConnectFailed 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 nullhandler- the function that will be called when the primary could not be obtained; may not be null- Returns:
- the client, or
nullif no primary could be found for the replica set
-
clientForPrimary
protected com.mongodb.client.MongoClient clientForPrimary(ReplicaSet replicaSet)
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
nullif no primary could be found for the replica set
-
-