public class ConnectionContext extends Object implements AutoCloseable
| Modifier and Type | Class and Description |
|---|---|
static class |
ConnectionContext.MongoPrimary
A supplier of a client that connects only to the primary of a replica set.
|
static interface |
ConnectionContext.PrimaryConnectFailed |
| Modifier and Type | Field and Description |
|---|---|
protected Configuration |
config |
private static org.slf4j.Logger |
LOGGER |
private static Duration |
PAUSE_AFTER_ERROR
A pause between failed MongoDB operations to prevent CPU throttling and DoS of
target MongoDB database.
|
protected MongoClients |
pool |
protected DelayStrategy |
primaryBackoffStrategy |
protected ReplicaSets |
replicaSets |
protected boolean |
useHostsAsSeeds |
| Constructor and Description |
|---|
ConnectionContext(Configuration config) |
| Modifier and Type | Method and Description |
|---|---|
com.mongodb.client.MongoClient |
clientFor(List<com.mongodb.ServerAddress> addresses) |
com.mongodb.client.MongoClient |
clientFor(String seedAddresses) |
protected com.mongodb.client.MongoClient |
clientForPrimary(ReplicaSet replicaSet)
Obtain a client that talks only to the primary node of the replica set.
|
com.mongodb.client.MongoClient |
clientForReplicaSet(ReplicaSet replicaSet) |
MongoClients |
clients() |
void |
close() |
String |
hosts() |
protected org.slf4j.Logger |
logger() |
int |
maxConnectionAttemptsForPrimary() |
boolean |
performSnapshotEvenIfNotNeeded() |
Duration |
pollInterval() |
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.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.
|
ReplicaSets |
replicaSets() |
void |
shutdown() |
private static final Duration PAUSE_AFTER_ERROR
private static final org.slf4j.Logger LOGGER
protected final Configuration config
protected final MongoClients pool
protected final ReplicaSets replicaSets
protected final DelayStrategy primaryBackoffStrategy
protected final boolean useHostsAsSeeds
public ConnectionContext(Configuration config)
config - the configurationpublic void shutdown()
public final void close()
close in interface AutoCloseableprotected org.slf4j.Logger logger()
public MongoClients clients()
public ReplicaSets replicaSets()
public boolean performSnapshotEvenIfNotNeeded()
public com.mongodb.client.MongoClient clientForReplicaSet(ReplicaSet replicaSet)
public com.mongodb.client.MongoClient clientFor(String seedAddresses)
public com.mongodb.client.MongoClient clientFor(List<com.mongodb.ServerAddress> addresses)
public String hosts()
public Duration pollInterval()
public int maxConnectionAttemptsForPrimary()
public ConnectionContext.MongoPrimary primaryFor(ReplicaSet replicaSet, Filters filters, BiConsumer<String,Throwable> errorHandler)
replicaSet - the replica set information; may not be nullfilters - the filter configurationerrorHandler - the function to be called whenever the primary is unable to
execute an operation to completion; may be nullnull if no primary could be found for the replica setprotected Supplier<com.mongodb.client.MongoClient> primaryClientFor(ReplicaSet replicaSet)
replicaSet - the replica set information; may not be nullnull if no primary could be found for the replica setprotected Supplier<com.mongodb.client.MongoClient> primaryClientFor(ReplicaSet replicaSet, ConnectionContext.PrimaryConnectFailed handler)
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 nullnull if no primary could be found for the replica setprotected com.mongodb.client.MongoClient clientForPrimary(ReplicaSet replicaSet)
replicaSet - the replica set information; may not be nullnull if no primary could be found for the replica setCopyright © 2021 JBoss by Red Hat. All rights reserved.