Package io.debezium.connector.mongodb
Class MongoClients
- java.lang.Object
-
- io.debezium.connector.mongodb.MongoClients
-
@ThreadSafe public class MongoClients extends Object
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 Classes Modifier and Type Class Description static classMongoClients.BuilderConfigures and builds a ConnectionPool.
-
Field Summary
Fields Modifier and Type Field Description private Map<List<com.mongodb.ServerAddress>,com.mongodb.client.MongoClient>connectionsprivate Map<com.mongodb.ServerAddress,com.mongodb.client.MongoClient>directConnectionsprivate com.mongodb.MongoClientSettings.Buildersettings
-
Constructor Summary
Constructors Modifier Constructor Description privateMongoClients(com.mongodb.MongoClientSettings.Builder settings)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()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.MongoClientclientFor(String addressString)Obtain 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 Detail
-
directConnections
private final Map<com.mongodb.ServerAddress,com.mongodb.client.MongoClient> directConnections
-
connections
private final Map<List<com.mongodb.ServerAddress>,com.mongodb.client.MongoClient> connections
-
settings
private final com.mongodb.MongoClientSettings.Builder settings
-
-
Method Detail
-
create
public static MongoClients.Builder 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
public com.mongodb.client.MongoClient clientFor(String addressString)
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
public com.mongodb.client.MongoClient clientForMembers(String addressList)
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
protected com.mongodb.client.MongoClient connection(List<com.mongodb.ServerAddress> addresses)
-
-