Skip to content

Commit 380c2c9

Browse files
committed
Added async support for com.mongodb.MongoClientSettings
Deprecated async.client.MongoClientSettings Unifies configuration for the async and sync packages JAVA-2837
1 parent 7f979d2 commit 380c2c9

23 files changed

+185
-90
lines changed

docs/reference/content/driver-async/getting-started/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ The connection string mostly follows [RFC 3986](http://tools.ietf.org/html/rfc39
134134
MongoClient mongoClient = MongoClients.create(new ConnectionString("mongodb://localhost"));
135135
```
136136

137-
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.async.client.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.html">}}) object:
137+
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.html">}}) object:
138138

139139
```java
140140
ClusterSettings clusterSettings = ClusterSettings.builder()

docs/reference/content/driver-async/tutorials/compression.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ In all cases the driver will use the first compressor in the list for which the
5555

5656
```java
5757
import com.mongodb.connection.ClusterSettings;
58-
import com.mongodb.async.client.MongoClientSettings;
5958
import com.mongodb.async.client.MongoClients;
6059
import com.mongodb.async.client.MongoClient;
60+
import com.mongodb.MongoClientSettings;
6161
import com.mongodb.MongoCompressor;
6262
import java.util.Arrays;
6363

6464
```
6565

66-
To specify compression with [`MongoClientSettings`]({{<apiref "com/mongodb/async/client/MongoClientSettings">}}), set the `compressors` property
66+
To specify compression with [`MongoClientSettings`]({{<apiref "com/mongodb/MongoClientSettings">}}), set the `compressors` property
6767
to a list of `MongoCompressor` instances:
6868

6969
```java
@@ -107,4 +107,3 @@ As with configuration with a URI, the driver will use the first compressor in th
107107
As the JDK has no built-in support for Snappy, the driver takes a dependency on an existing open-source Snappy implementation. See the
108108
[snappy-java Github repository](https://github.com/xerial/snappy-java) for details.
109109

110-

docs/reference/content/driver-async/tutorials/connect-to-mongodb.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ To connect to a standalone MongoDB instance:
7676
MongoClient mongoClient = MongoClients.create(new ConnectionString("mongodb://localhost"));
7777
```
7878

79-
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.async.client.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.html">}}) object. To specify the host information, use the [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}).
79+
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.html">}}) object. To specify the host information, use the [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}).
8080

8181
```java
8282
ClusterSettings clusterSettings = ClusterSettings.builder()
@@ -88,7 +88,7 @@ To connect to a standalone MongoDB instance:
8888
```
8989

9090
{{% note class="tip" %}}
91-
[`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings" >}}) provide more configuration options than a connection string.
91+
[`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings" >}}) provide more configuration options than a connection string.
9292
{{% /note %}}
9393

9494
## Connect to a Replica Set
@@ -132,7 +132,7 @@ MongoDB will auto-discover the primary and the secondaries.
132132
new ConnectionString("mongodb://host1:27017,host2:27017,host3:27017/?replicaSet=myReplicaSet"));
133133
```
134134

135-
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.async.client.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.html">}}) object. To specify the host information of the replica set members, use [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}).
135+
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.html">}}) object. To specify the host information of the replica set members, use [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}).
136136

137137
```java
138138
ClusterSettings clusterSettings = ClusterSettings.builder()
@@ -173,7 +173,7 @@ To connect to a single `mongos` instance:
173173
new ConnectionString("mongodb://localhost"));
174174
```
175175

176-
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.async.client.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.html">}}) object. To specify the host information of the `mongos` instance, use [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}):
176+
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.html">}}) object. To specify the host information of the `mongos` instance, use [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}):
177177

178178
```java
179179
ClusterSettings clusterSettings = ClusterSettings.builder()
@@ -200,7 +200,7 @@ To connect to multiple `mongos` instances, specify the host and port of the `mon
200200
new ConnectionString("mongodb://host1:27017,host2:27017"));
201201
```
202202

203-
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.async.client.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.html">}}) object. To specify the host information of the `mongos` instances, use [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}):
203+
- You can call [`MongoClients.create()`]({{< apiref "com/mongodb/async/client/MongoClients.html#create-com.mongodb.MongoClientSettings-" >}}) with a [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.html">}}) object. To specify the host information of the `mongos` instances, use [`ClusterSettings`]({{<apiref "com/mongodb/connection/ClusterSettings.html">}}):
204204

205205

206206
```java
@@ -246,7 +246,7 @@ To configure the driver to use Netty,
246246
MongoClient client = MongoClients.create("mongodb://localhost/?streamType=netty");
247247
```
248248

249-
- Configure [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.Builder.html#streamFactoryFactory-com.mongodb.connection.StreamFactoryFactory-">}}) with the `StreamFactory` set to use Netty:
249+
- Configure [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.Builder.html#streamFactoryFactory-com.mongodb.connection.StreamFactoryFactory-">}}) with the `StreamFactory` set to use Netty:
250250

251251
```java
252252
MongoClient client = MongoClients.create(MongoClientSettings.builder()

docs/reference/content/driver-async/tutorials/perform-read-operations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ For read operations on [replica sets]({{<docsref "replication/">}}) or [sharded
221221

222222
- In a [`MongoClient()`]({{< apiref "com/mongodb/async/client/MongoClient.html" >}})
223223

224-
- Via [`MongoClientSettings`]({{<apiref "com/mongodb/async/client/MongoClientSettings.html">}}), as in the following example:
224+
- Via [`MongoClientSettings`]({{<apiref "com/mongodb/MongoClientSettings.html">}}), as in the following example:
225225

226226
```java
227227
ClusterSettings clusterSettings = ClusterSettings.builder()
@@ -280,7 +280,7 @@ For read operations on [replica sets]({{<docsref "replication/">}}) or [sharded
280280

281281
- In a [`MongoClient()`]({{< apiref "com/mongodb/async/client/MongoClient.html" >}})
282282

283-
- Via [`MongoClientSettings`]({{<apiref "com/mongodb/async/client/MongoClientSettings.html">}}), as in the following example:
283+
- Via [`MongoClientSettings`]({{<apiref "com/mongodb/MongoClientSettings.html">}}), as in the following example:
284284

285285
```java
286286
ClusterSettings clusterSettings = ClusterSettings.builder()

docs/reference/content/driver-async/tutorials/perform-write-operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Applications can configure [write concern]({{<docsref "reference/write-concern">
339339

340340
- In a [`MongoClient()`]({{< apiref "com/mongodb/async/client/MongoClient.html" >}})
341341

342-
- Via [`MongoClientSettings`]({{<apiref "com/mongodb/async/client/MongoClientSettings.html">}}), as in the following example:
342+
- Via [`MongoClientSettings`]({{<apiref "com/mongodb/MongoClientSettings.html">}}), as in the following example:
343343

344344
```java
345345
ClusterSettings clusterSettings = ClusterSettings.builder()

docs/reference/content/driver-async/tutorials/ssl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You can also specify the connection string via the [`ConnectionString`]({{< apir
3636

3737
### Via `MongoClientSettings`
3838

39-
To specify TLS/SSL with [`MongoClientSettings`]({{< apiref "com/mongodb/async/client/MongoClientSettings.Builder.html#streamFactoryFactory-com.mongodb.connection.StreamFactoryFactory-">}}) ,
39+
To specify TLS/SSL with [`MongoClientSettings`]({{< apiref "com/mongodb/MongoClientSettings.Builder.html#streamFactoryFactory-com.mongodb.connection.StreamFactoryFactory-">}}) ,
4040
set the ``sslEnabled`` property to ``true``, and the stream factory to
4141
[`NettyStreamFactoryFactory`]({{< apiref "com/mongodb/connection/netty/NettyStreamFactoryFactory" >}}), as in
4242

driver-async/src/examples/documentation/DocumentationSamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import com.mongodb.Block;
2020
import com.mongodb.MongoCompressor;
2121
import com.mongodb.MongoNamespace;
22+
import com.mongodb.MongoClientSettings;
2223
import com.mongodb.async.FutureResultCallback;
2324
import com.mongodb.async.SingleResultCallback;
2425
import com.mongodb.async.client.DatabaseTestCase;
2526
import com.mongodb.async.client.FindIterable;
2627
import com.mongodb.async.client.MongoClient;
27-
import com.mongodb.async.client.MongoClientSettings;
2828
import com.mongodb.async.client.MongoClients;
2929
import com.mongodb.async.client.MongoCollection;
3030
import com.mongodb.client.result.DeleteResult;

driver-async/src/main/com/mongodb/async/client/MongoClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public interface MongoClient extends Closeable {
7171
* <p>Note: {@link MongoClientSettings} is immutable.</p>
7272
*
7373
* @return the settings
74+
* @deprecated this method is being removed
7475
*/
76+
@Deprecated
7577
MongoClientSettings getSettings();
7678

7779
/**

driver-async/src/main/com/mongodb/async/client/MongoClientImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static com.mongodb.assertions.Assertions.notNull;
3838
import static com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback;
3939

40+
@SuppressWarnings("deprecation")
4041
class MongoClientImpl implements MongoClient {
4142
private static final Logger LOGGER = Loggers.getLogger("client");
4243
private final Cluster cluster;

driver-async/src/main/com/mongodb/async/client/MongoClientSettings.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
* Various settings to control the behavior of a {@code MongoClient}.
4949
*
5050
* @since 3.0
51+
* @deprecated use {@link com.mongodb.MongoClientSettings} instead
5152
*/
5253
@Immutable
54+
@Deprecated
5355
public final class MongoClientSettings {
5456
private final com.mongodb.MongoClientSettings wrapped;
5557
private final SocketSettings heartbeatSocketSettings;
@@ -74,46 +76,40 @@ public static Builder builder(final MongoClientSettings settings) {
7476
return new Builder(settings);
7577
}
7678

79+
static MongoClientSettings createFromClientSettings(final com.mongodb.MongoClientSettings wrapped) {
80+
return new Builder(wrapped).build();
81+
}
82+
7783
/**
7884
* A builder for {@code MongoClientSettings} so that {@code MongoClientSettings} can be immutable, and to support easier construction
7985
* through chaining.
8086
*/
8187
@NotThreadSafe
8288
public static final class Builder {
89+
private final com.mongodb.MongoClientSettings.Builder wrappedBuilder;
8390
private List<MongoCredential> credentialList = Collections.emptyList();
84-
private final com.mongodb.MongoClientSettings.Builder wrappedBuilder = com.mongodb.MongoClientSettings.builder();
8591
private SocketSettings.Builder heartbeatSocketSettingsBuilder = null;
8692

8793
private Builder() {
94+
wrappedBuilder = com.mongodb.MongoClientSettings.builder();
8895
}
8996

90-
@SuppressWarnings("deprecation")
91-
private Builder(final MongoClientSettings settings) {
97+
private Builder(final com.mongodb.MongoClientSettings settings) {
9298
notNull("settings", settings);
93-
credentialList = new ArrayList<MongoCredential>(settings.credentialList);
94-
95-
wrappedBuilder.commandListenerList(new ArrayList<CommandListener>(settings.getCommandListeners()));
96-
wrappedBuilder.codecRegistry(settings.getCodecRegistry());
97-
wrappedBuilder.readPreference(settings.getReadPreference());
98-
wrappedBuilder.writeConcern(settings.getWriteConcern());
99-
wrappedBuilder.retryWrites(settings.getRetryWrites());
100-
wrappedBuilder.readConcern(settings.getReadConcern());
101-
wrappedBuilder.applicationName(settings.getApplicationName());
102-
wrappedBuilder.compressorList(new ArrayList<MongoCompressor>(settings.getCompressorList()));
103-
99+
wrappedBuilder = com.mongodb.MongoClientSettings.builder(settings);
104100
MongoCredential credential = settings.getCredential();
105101
if (credential != null) {
106-
wrappedBuilder.credential(credential);
102+
credentialList(singletonList(credential));
107103
}
104+
}
108105

109-
clusterSettings(settings.getClusterSettings());
110-
serverSettings(settings.getServerSettings());
111-
socketSettings(settings.getSocketSettings());
106+
@SuppressWarnings("deprecation")
107+
private Builder(final MongoClientSettings settings) {
108+
this(notNull("settings", settings).wrapped);
109+
credentialList = new ArrayList<MongoCredential>(settings.credentialList);
112110
if (settings.heartbeatSocketSettings != null) {
113111
heartbeatSocketSettings(settings.heartbeatSocketSettings);
114112
}
115-
connectionPoolSettings(settings.getConnectionPoolSettings());
116-
sslSettings(settings.getSslSettings());
117113
}
118114

119115
/**
@@ -631,9 +627,9 @@ public SocketSettings getSocketSettings() {
631627

632628
/**
633629
* Gets the connection settings for the heartbeat thread (the background task that checks the state of the cluster) wrapped in a
634-
* settings object. This settings object uses the values for heartbeatConnectTimeout, heartbeatSocketTimeout and socketKeepAlive.
630+
* settings object.
635631
*
636-
* @return a SocketSettings object populated with the heartbeat connection settings from this {@code MongoClientSettings} instance.
632+
* @return the SocketSettings for the heartbeat thread
637633
* @see com.mongodb.connection.SocketSettings
638634
*/
639635
public SocketSettings getHeartbeatSocketSettings() {

0 commit comments

Comments
 (0)