public static class ConnectionContext.MongoPrimary extends Object
| Modifier and Type | Field and Description |
|---|---|
private BiConsumer<String,Throwable> |
errorHandler |
private Filters |
filters |
private Supplier<com.mongodb.client.MongoClient> |
primaryConnectionSupplier |
private ReplicaSet |
replicaSet |
private AtomicBoolean |
running |
| Modifier | Constructor and Description |
|---|---|
protected |
MongoPrimary(ConnectionContext context,
ReplicaSet replicaSet,
Filters filters,
BiConsumer<String,Throwable> errorHandler) |
| Modifier and Type | Method and Description |
|---|---|
com.mongodb.ServerAddress |
address()
Get the address of the primary node, if there is one.
|
List<CollectionId> |
collections()
Use the primary to get the identifiers of all the collections in the replica set, applying the current
collection filter configuration.
|
Set<String> |
databaseNames()
Use the primary to get the names of all the databases in the replica set, applying the current database
filter configuration.
|
void |
execute(String desc,
Consumer<com.mongodb.client.MongoClient> operation)
Execute the supplied operation using the primary, blocking until a primary is available.
|
<T> T |
execute(String desc,
Function<com.mongodb.client.MongoClient,T> operation)
Execute the supplied operation using the primary, blocking until a primary is available.
|
void |
executeBlocking(String desc,
BlockingConsumer<com.mongodb.client.MongoClient> operation)
Execute the supplied operation using the primary, blocking until a primary is available.
|
private boolean |
isRunning() |
ReplicaSet |
replicaSet()
Get the replica set.
|
void |
stop()
Terminates the execution loop of the current primary
|
private final ReplicaSet replicaSet
private final Supplier<com.mongodb.client.MongoClient> primaryConnectionSupplier
private final Filters filters
private final BiConsumer<String,Throwable> errorHandler
private final AtomicBoolean running
protected MongoPrimary(ConnectionContext context, ReplicaSet replicaSet, Filters filters, BiConsumer<String,Throwable> errorHandler)
public ReplicaSet replicaSet()
public com.mongodb.ServerAddress address()
null if there is currently no primarypublic void execute(String desc, Consumer<com.mongodb.client.MongoClient> operation)
desc - the description of the operation, for logging purposesoperation - the operation to be performed on the primary.public <T> T execute(String desc, Function<com.mongodb.client.MongoClient,T> operation)
desc - the description of the operation, for logging purposesoperation - the operation to be performed on the primarypublic void executeBlocking(String desc, BlockingConsumer<com.mongodb.client.MongoClient> operation) throws InterruptedException
desc - the description of the operation, for logging purposesoperation - the operation to be performed on the primary.InterruptedException - if the operation was interruptedpublic Set<String> databaseNames()
public List<CollectionId> collections()
private boolean isRunning()
public void stop()
Copyright © 2021 JBoss by Red Hat. All rights reserved.