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 org.slf4j.Logger |
logger |
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.MongoClient |
clientFor(List<com.mongodb.ServerAddress> addresses) |
com.mongodb.MongoClient |
clientFor(String seedAddresses) |
protected com.mongodb.MongoClient |
clientForPrimary(ReplicaSet replicaSet)
Obtain a client that talks only to the primary node of the replica set.
|
com.mongodb.MongoClient |
clientForReplicaSet(ReplicaSet replicaSet) |
MongoClients |
clients() |
void |
close() |
LoggingContext.PreviousContext |
configureLoggingContext(String contextName)
Configure the logger's Mapped Diagnostic Context (MDC) properties for the thread making this call.
|
String |
hosts() |
protected org.slf4j.Logger |
logger() |
int |
maxConnectionAttemptsForPrimary() |
int |
maxNumberOfCopyThreads() |
boolean |
performSnapshotEvenIfNotNeeded() |
int |
pollPeriodInSeconds() |
protected Supplier<com.mongodb.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.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,
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() |
String |
serverName() |
void |
shutdown() |
private 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.MongoClient clientForReplicaSet(ReplicaSet replicaSet)
public com.mongodb.MongoClient clientFor(String seedAddresses)
public com.mongodb.MongoClient clientFor(List<com.mongodb.ServerAddress> addresses)
public String hosts()
public int pollPeriodInSeconds()
public int maxConnectionAttemptsForPrimary()
public int maxNumberOfCopyThreads()
public String serverName()
public ConnectionContext.MongoPrimary primaryFor(ReplicaSet replicaSet, BiConsumer<String,Throwable> errorHandler)
replicaSet - the replica set information; may not be nullerrorHandler - 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.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.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.MongoClient clientForPrimary(ReplicaSet replicaSet)
replicaSet - the replica set information; may not be nullnull if no primary could be found for the replica setpublic LoggingContext.PreviousContext configureLoggingContext(String contextName)
contextName - the name of the context; may not be nullIllegalArgumentException - if contextName is nullCopyright © 2017 JBoss by Red Hat. All rights reserved.