summaryrefslogtreecommitdiff
path: root/src/mongo/client/connection_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/client/connection_string.h')
-rw-r--r--src/mongo/client/connection_string.h57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/mongo/client/connection_string.h b/src/mongo/client/connection_string.h
index 98b66bef986..77f5f73a277 100644
--- a/src/mongo/client/connection_string.h
+++ b/src/mongo/client/connection_string.h
@@ -52,7 +52,7 @@ class MongoURI;
* samples:
* server
* server:port
- * foo/server:port,server:port SET
+ * foo/server:port,server:port kReplicaSet
*
* Typical use:
*
@@ -62,14 +62,20 @@ class MongoURI;
*/
class ConnectionString {
public:
- enum ConnectionType { INVALID, MASTER, SET, CUSTOM, LOCAL };
+ enum class ConnectionType { kInvalid = 0, kStandalone, kReplicaSet, kCustom, kLocal };
ConnectionString() = default;
/**
* Constructs a connection string representing a replica set.
*/
- static ConnectionString forReplicaSet(StringData setName, std::vector<HostAndPort> servers);
+ static ConnectionString forReplicaSet(StringData replicaSetName,
+ std::vector<HostAndPort> servers);
+
+ /**
+ * Constructs a connection string representing a list of standalone servers.
+ */
+ static ConnectionString forStandalones(std::vector<HostAndPort> servers);
/**
* Constructs a local connection string.
@@ -77,34 +83,42 @@ public:
static ConnectionString forLocal();
/**
- * Creates a MASTER connection string with the specified server.
+ * Creates a standalone connection string with the specified server.
*/
explicit ConnectionString(const HostAndPort& server);
/**
- * Creates a connection string from an unparsed list of servers, type, and setName.
+ * Creates a connection string from an unparsed list of servers, type, and replicaSetName.
*/
- ConnectionString(ConnectionType type, const std::string& s, const std::string& setName);
+ ConnectionString(ConnectionType type, const std::string& s, const std::string& replicaSetName);
/**
- * Creates a connection string from a pre-parsed list of servers, type, and setName.
+ * Creates a connection string from a pre-parsed list of servers, type, and replicaSetName.
*/
ConnectionString(ConnectionType type,
std::vector<HostAndPort> servers,
- const std::string& setName);
+ const std::string& replicaSetName);
ConnectionString(const std::string& s, ConnectionType connType);
bool isValid() const {
- return _type != INVALID;
+ return _type != ConnectionType::kInvalid;
+ }
+
+ explicit operator bool() const {
+ return isValid();
}
const std::string& toString() const {
return _string;
}
+ const std::string& getReplicaSetName() const {
+ return _replicaSetName;
+ }
+
const std::string& getSetName() const {
- return _setName;
+ return getReplicaSetName();
}
const std::vector<HostAndPort>& getServers() const {
@@ -187,22 +201,25 @@ public:
private:
/**
- * Creates a SET connection string with the specified set name and servers.
+ * Creates a replica set connection string with the specified name and servers.
*/
- ConnectionString(StringData setName, std::vector<HostAndPort> servers);
+ ConnectionString(StringData replicaSetName, std::vector<HostAndPort> servers);
/**
- * Creates a connection string with the specified type. Used for creating LOCAL strings.
+ * Creates a connection string with the specified type.
+ *
+ * This ctor is mostly used to create ConnectionStrings to the current node with
+ * ConnectionType::kLocal.
*/
explicit ConnectionString(ConnectionType connType);
void _fillServers(std::string s);
void _finishInit();
- ConnectionType _type{INVALID};
+ ConnectionType _type{ConnectionType::kInvalid};
std::vector<HostAndPort> _servers;
std::string _string;
- std::string _setName;
+ std::string _replicaSetName;
static Mutex _connectHookMutex;
static ConnectionHook* _connectHook;
@@ -218,4 +235,14 @@ inline StringBuilder& operator<<(StringBuilder& sb, const ConnectionString& cs)
return sb;
}
+inline std::ostream& operator<<(std::ostream& ss, const ConnectionString::ConnectionType& ct) {
+ ss << ConnectionString::typeToString(ct);
+ return ss;
+}
+
+inline StringBuilder& operator<<(StringBuilder& sb, const ConnectionString::ConnectionType& ct) {
+ sb << ConnectionString::typeToString(ct);
+ return sb;
+}
+
} // namespace mongo