Skip to content

Commit 4b019f3

Browse files
committed
Merge branch 'master' into CSOT
2 parents 41a3902 + 2260ab5 commit 4b019f3

File tree

14 files changed

+1788
-113
lines changed

14 files changed

+1788
-113
lines changed

driver-core/src/main/com/mongodb/assertions/Assertions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static <T> Iterable<T> notNullElements(final String name, final Iterable<
9292
public static <T> T notNull(final String name, final T value, final SingleResultCallback<?> callback) {
9393
if (value == null) {
9494
IllegalArgumentException exception = new IllegalArgumentException(name + " can not be null");
95-
callback.onResult(null, exception);
95+
callback.completeExceptionally(exception);
9696
throw exception;
9797
}
9898
return value;
@@ -122,7 +122,7 @@ public static void isTrue(final String name, final boolean condition) {
122122
public static void isTrue(final String name, final boolean condition, final SingleResultCallback<?> callback) {
123123
if (!condition) {
124124
IllegalStateException exception = new IllegalStateException("state should be: " + name);
125-
callback.onResult(null, exception);
125+
callback.completeExceptionally(exception);
126126
throw exception;
127127
}
128128
}

driver-core/src/main/com/mongodb/connection/AsyncCompletionHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.mongodb.connection;
1818

19+
import com.mongodb.internal.async.SingleResultCallback;
1920
import com.mongodb.lang.Nullable;
2021

2122
/**
@@ -38,4 +39,17 @@ public interface AsyncCompletionHandler<T> {
3839
* @param t the exception that describes the failure
3940
*/
4041
void failed(Throwable t);
42+
43+
/**
44+
* @return this handler as a callback
45+
*/
46+
default SingleResultCallback<T> asCallback() {
47+
return (r, t) -> {
48+
if (t != null) {
49+
failed(t);
50+
} else {
51+
completed(r);
52+
}
53+
};
54+
}
4155
}

driver-core/src/main/com/mongodb/connection/ClusterSettings.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ public Builder srvHost(final String srvHost) {
151151

152152
/**
153153
* Sets the maximum number of hosts to connect to when using SRV protocol.
154+
* This setting is not used if {@link #getMode()} is {@link ClusterConnectionMode#LOAD_BALANCED}.
154155
*
155156
* @param srvMaxHosts the maximum number of hosts to connect to when using SRV protocol
156157
* @return this
157158
* @since 4.4
159+
* @see #getSrvMaxHosts()
158160
*/
159161
public Builder srvMaxHosts(final Integer srvMaxHosts) {
160162
this.srvMaxHosts = srvMaxHosts;
@@ -168,15 +170,16 @@ public Builder srvMaxHosts(final Integer srvMaxHosts) {
168170
* The SRV resource record (<a href="https://www.rfc-editor.org/rfc/rfc2782">RFC 2782</a>)
169171
* service name, which is limited to 15 characters
170172
* (<a href="https://www.rfc-editor.org/rfc/rfc6335#section-5.1">RFC 6335 section 5.1</a>).
171-
* If specified, it is combined with the single host name specified by
172-
* {@link #getHosts()} as follows: {@code _srvServiceName._tcp.hostName}. The combined string is an SRV resource record
173+
* It is combined with the host name specified by
174+
* {@link #getSrvHost()} as follows: {@code _srvServiceName._tcp.hostName}. The combined string is an SRV resource record
173175
* name (<a href="https://www.rfc-editor.org/rfc/rfc1035#section-2.3.1">RFC 1035 section 2.3.1</a>), which is limited to 255
174176
* characters (<a href="https://www.rfc-editor.org/rfc/rfc1035#section-2.3.4">RFC 1035 section 2.3.4</a>).
175177
* </p>
176178
*
177179
* @param srvServiceName the SRV service name
178180
* @return this
179181
* @since 4.5
182+
* @see #getSrvServiceName()
180183
*/
181184
public Builder srvServiceName(final String srvServiceName) {
182185
this.srvServiceName = notNull("srvServiceName", srvServiceName);
@@ -219,6 +222,7 @@ public Builder mode(final ClusterConnectionMode mode) {
219222

220223
/**
221224
* Sets the required replica set name for the cluster.
225+
* This setting is not used if {@link #getMode()} is {@link ClusterConnectionMode#LOAD_BALANCED}.
222226
*
223227
* @param requiredReplicaSetName the required replica set name.
224228
* @return this
@@ -231,9 +235,11 @@ public Builder requiredReplicaSetName(@Nullable final String requiredReplicaSetN
231235

232236
/**
233237
* Sets the required cluster type for the cluster.
238+
* This setting is not used if {@link #getMode()} is {@link ClusterConnectionMode#LOAD_BALANCED}.
234239
*
235240
* @param requiredClusterType the required cluster type
236241
* @return this
242+
* @see #getRequiredClusterType()
237243
*/
238244
public Builder requiredClusterType(final ClusterType requiredClusterType) {
239245
this.requiredClusterType = notNull("requiredClusterType", requiredClusterType);
@@ -384,9 +390,11 @@ public String getSrvHost() {
384390

385391
/**
386392
* Gets the maximum number of hosts to connect to when using SRV protocol.
393+
* This setting is not used if {@link #getMode()} is {@link ClusterConnectionMode#LOAD_BALANCED}.
387394
*
388395
* @return the maximum number of hosts to connect to when using SRV protocol. Defaults to null.
389396
* @since 4.4
397+
* @see Builder#srvMaxHosts(Integer)
390398
*/
391399
@Nullable
392400
public Integer getSrvMaxHosts() {
@@ -400,14 +408,15 @@ public Integer getSrvMaxHosts() {
400408
* The SRV resource record (<a href="https://www.rfc-editor.org/rfc/rfc2782">RFC 2782</a>)
401409
* service name, which is limited to 15 characters
402410
* (<a href="https://www.rfc-editor.org/rfc/rfc6335#section-5.1">RFC 6335 section 5.1</a>).
403-
* If specified, it is combined with the single host name specified by
404-
* {@link #getHosts()} as follows: {@code _srvServiceName._tcp.hostName}. The combined string is an SRV resource record
411+
* It is combined with the host name specified by
412+
* {@link #getSrvHost()} as follows: {@code _srvServiceName._tcp.hostName}. The combined string is an SRV resource record
405413
* name (<a href="https://www.rfc-editor.org/rfc/rfc1035#section-2.3.1">RFC 1035 section 2.3.1</a>), which is limited to 255
406414
* characters (<a href="https://www.rfc-editor.org/rfc/rfc1035#section-2.3.4">RFC 1035 section 2.3.4</a>).
407415
* </p>
408416
*
409417
* @return the SRV service name, which defaults to {@code "mongodb"}
410418
* @since 4.5
419+
* @see Builder#srvServiceName(String)
411420
*/
412421
public String getSrvServiceName() {
413422
return srvServiceName;
@@ -433,15 +442,18 @@ public ClusterConnectionMode getMode() {
433442

434443
/**
435444
* Gets the required cluster type
445+
* This setting is not used if {@link #getMode()} is {@link ClusterConnectionMode#LOAD_BALANCED}.
436446
*
437447
* @return the required cluster type
448+
* @see Builder#requiredClusterType(ClusterType)
438449
*/
439450
public ClusterType getRequiredClusterType() {
440451
return requiredClusterType;
441452
}
442453

443454
/**
444455
* Gets the required replica set name.
456+
* This setting is not used if {@link #getMode()} is {@link ClusterConnectionMode#LOAD_BALANCED}.
445457
*
446458
* @return the required replica set name
447459
* @see Builder#requiredReplicaSetName(String)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.internal.async;
18+
19+
/**
20+
* See {@link AsyncRunnable}.
21+
* <p>
22+
* This class is not part of the public API and may be removed or changed at any time
23+
*/
24+
@FunctionalInterface
25+
public interface AsyncConsumer<T> extends AsyncFunction<T, Void> {
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.internal.async;
18+
19+
import com.mongodb.lang.Nullable;
20+
21+
/**
22+
* See {@link AsyncRunnable}
23+
* <p>
24+
* This class is not part of the public API and may be removed or changed at any time
25+
*/
26+
@FunctionalInterface
27+
public interface AsyncFunction<T, R> {
28+
/**
29+
* This should not be called externally, but should be implemented as a
30+
* lambda. To "finish" an async chain, use one of the "finish" methods.
31+
*
32+
* @param value A {@code @}{@link Nullable} argument of the asynchronous function.
33+
* @param callback the callback
34+
*/
35+
void unsafeFinish(T value, SingleResultCallback<R> callback);
36+
}

0 commit comments

Comments
 (0)