-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the
serverMonitoringMode
connection string option
This change is with accordance to source/uri-options/uri-options.rst. JAVA-4936
- Loading branch information
Showing
10 changed files
with
420 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
driver-core/src/main/com/mongodb/connection/ServerMonitoringMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.connection; | ||
|
||
import static com.mongodb.assertions.Assertions.notNull; | ||
import static java.lang.String.format; | ||
|
||
/** | ||
* The server monitoring mode, which defines the monitoring protocol to use. | ||
* | ||
* @since 5.1 | ||
*/ | ||
public enum ServerMonitoringMode { | ||
/** | ||
* Use the streaming protocol whe the server supports it or fall back to the polling protocol otherwise. | ||
*/ | ||
STREAM("stream"), | ||
/** | ||
* Use the polling protocol. | ||
*/ | ||
POLL("poll"), | ||
/** | ||
* Behave the same as {@link #POLL} if running in a FaaS environment, otherwise behave as {@link #STREAM}. | ||
* This is the default. | ||
*/ | ||
AUTO("auto"); | ||
|
||
private final String value; | ||
|
||
ServerMonitoringMode(final String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Parses a string into {@link ServerMonitoringMode}. | ||
* | ||
* @param serverMonitoringMode A server monitoring mode string. | ||
* @return The corresponding {@link ServerMonitoringMode} value. | ||
* @see #getValue() | ||
*/ | ||
public static ServerMonitoringMode fromString(final String serverMonitoringMode) { | ||
notNull("serverMonitoringMode", serverMonitoringMode); | ||
for (ServerMonitoringMode mode : ServerMonitoringMode.values()) { | ||
if (serverMonitoringMode.equalsIgnoreCase(mode.value)) { | ||
return mode; | ||
} | ||
} | ||
throw new IllegalArgumentException(format("'%s' is not a valid %s", | ||
serverMonitoringMode, ServerMonitoringMode.class.getSimpleName())); | ||
} | ||
|
||
/** | ||
* The string value. | ||
* | ||
* @return The string value. | ||
* @see #fromString(String) | ||
*/ | ||
public String getValue() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
driver-core/src/test/resources/uri-options/sdam-options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"description": "serverMonitoringMode=auto", | ||
"uri": "mongodb://example.com/?serverMonitoringMode=auto", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"serverMonitoringMode": "auto" | ||
} | ||
}, | ||
{ | ||
"description": "serverMonitoringMode=stream", | ||
"uri": "mongodb://example.com/?serverMonitoringMode=stream", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"serverMonitoringMode": "stream" | ||
} | ||
}, | ||
{ | ||
"description": "serverMonitoringMode=poll", | ||
"uri": "mongodb://example.com/?serverMonitoringMode=poll", | ||
"valid": true, | ||
"warning": false, | ||
"hosts": null, | ||
"auth": null, | ||
"options": { | ||
"serverMonitoringMode": "poll" | ||
} | ||
}, | ||
{ | ||
"description": "invalid serverMonitoringMode", | ||
"uri": "mongodb://example.com/?serverMonitoringMode=invalid", | ||
"valid": true, | ||
"warning": true, | ||
"hosts": null, | ||
"auth": null, | ||
"options": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.