Package io.debezium.connector.mongodb
Class MongoClients
java.lang.Object
io.debezium.connector.mongodb.MongoClients
A connection pool of MongoClient instances. This pool supports creating clients that communicate explicitly with a single
server, or clients that communicate with any members of a replica set or sharded cluster given a set of seed addresses.
- Author:
- Randall Hauch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfigures and builds a ConnectionPool. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<com.mongodb.ServerAddress,com.mongodb.client.MongoClient> private final com.mongodb.MongoClientSettings.Builder -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateMongoClients(com.mongodb.MongoClientSettings.Builder settings) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear out and close any open connections.com.mongodb.client.MongoClientclientFor(com.mongodb.ServerAddress address) Obtain a direct client connection to the specified server.com.mongodb.client.MongoClientObtain a direct client connection to the specified server.com.mongodb.client.MongoClientclientForMembers(com.mongodb.ServerAddress... seeds) Obtain a client connection to the replica set or cluster.com.mongodb.client.MongoClientclientForMembers(String addressList) Obtain a client connection to the replica set or cluster.com.mongodb.client.MongoClientclientForMembers(List<com.mongodb.ServerAddress> seedAddresses) Obtain a client connection to the replica set or cluster.protected com.mongodb.client.MongoClientconnection(List<com.mongodb.ServerAddress> addresses) static MongoClients.Buildercreate()Obtain a builder that can be used to configure andcreatea connection pool.protected com.mongodb.client.MongoClientdirectConnection(com.mongodb.ServerAddress address)
-
Field Details
-
directConnections
-
connections
-
settings
private final com.mongodb.MongoClientSettings.Builder settings
-
-
Constructor Details
-
MongoClients
private MongoClients(com.mongodb.MongoClientSettings.Builder settings)
-
-
Method Details
-
create
Obtain a builder that can be used to configure andcreatea connection pool.- Returns:
- the new builder; never null
-
clear
public void clear()Clear out and close any open connections. -
clientFor
Obtain a direct client connection to the specified server. This is typically used to connect to a standalone server, but it also can be used to obtain a client that will only use this server, even if the server is a member of a replica set or sharded cluster.The format of the supplied string is one of the following:
host:port host
wherehostcontains the resolvable hostname or IP address of the server, andportis the integral port number. If the port is not provided, thedefault portis used. If neither the host or port are provided (oraddressStringisnull), then an address will use thedefault hostanddefault port.- Parameters:
addressString- the string that contains the host and port of the server- Returns:
- the MongoClient instance; never null
-
clientFor
public com.mongodb.client.MongoClient clientFor(com.mongodb.ServerAddress address) Obtain a direct client connection to the specified server. This is typically used to connect to a standalone server, but it also can be used to obtain a client that will only use this server, even if the server is a member of a replica set or sharded cluster.- Parameters:
address- the address of the server to use- Returns:
- the MongoClient instance; never null
-
clientForMembers
Obtain a client connection to the replica set or cluster. The supplied addresses are used as seeds, and once a connection is established it will discover all of the members.The format of the supplied string is one of the following:
replicaSetName/host:port replicaSetName/host:port,host2:port2 replicaSetName/host:port,host2:port2,host3:port3 host:port host:port,host2:port2 host:port,host2:port2,host3:port3
wherereplicaSetNameis the name of the replica set,hostcontains the resolvable hostname or IP address of the server, andportis the integral port number. If the port is not provided, thedefault portis used. If neither the host or port are provided (oraddressStringisnull), then an address will use thedefault hostanddefault port.This method does not use the replica set name.
- Parameters:
addressList- the string containing a comma-separated list of host and port pairs, optionally preceded by a replica set name- Returns:
- the MongoClient instance; never null
-
clientForMembers
public com.mongodb.client.MongoClient clientForMembers(com.mongodb.ServerAddress... seeds) Obtain a client connection to the replica set or cluster. The supplied addresses are used as seeds, and once a connection is established it will discover all of the members.- Parameters:
seeds- the seed addresses- Returns:
- the MongoClient instance; never null
-
clientForMembers
public com.mongodb.client.MongoClient clientForMembers(List<com.mongodb.ServerAddress> seedAddresses) Obtain a client connection to the replica set or cluster. The supplied addresses are used as seeds, and once a connection is established it will discover all of the members.- Parameters:
seedAddresses- the seed addresses- Returns:
- the MongoClient instance; never null
-
directConnection
protected com.mongodb.client.MongoClient directConnection(com.mongodb.ServerAddress address) -
connection
-