* Represents the state of a Client. * * Exposes information on the connections maintained by a Client at a specific time. * * @alias module:metadata~ClientState * @constructor
| 29 | * @constructor |
| 30 | */ |
| 31 | class ClientState { |
| 32 | |
| 33 | /** |
| 34 | * Creates a new instance of <code>ClientState</code>. |
| 35 | * @param {Array<Host>} hosts |
| 36 | * @param {Object.<String, Number>} openConnections |
| 37 | * @param {Object.<String, Number>} inFlightQueries |
| 38 | */ |
| 39 | constructor(hosts, openConnections, inFlightQueries) { |
| 40 | this._hosts = hosts; |
| 41 | this._openConnections = openConnections; |
| 42 | this._inFlightQueries = inFlightQueries; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get an array of hosts to which the client is connected to. |
| 47 | * @return {Array<Host>} |
| 48 | */ |
| 49 | getConnectedHosts() { |
| 50 | return this._hosts; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets the amount of open connections to a given host. |
| 55 | * @param {Host} host |
| 56 | * @return {Number} |
| 57 | */ |
| 58 | getOpenConnections(host) { |
| 59 | if (!host) { |
| 60 | throw new errors.ArgumentError('Host is not defined'); |
| 61 | } |
| 62 | |
| 63 | return this._openConnections[host.address] || 0; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Gets the amount of queries that are currently being executed through a given host. |
| 68 | * <p> |
| 69 | * This corresponds to the number of queries that have been sent by the Client to server Host on one of its connections |
| 70 | * but haven't yet obtained a response. |
| 71 | * </p> |
| 72 | * @param {Host} host |
| 73 | * @return {Number} |
| 74 | */ |
| 75 | getInFlightQueries(host) { |
| 76 | if (!host) { |
| 77 | throw new errors.ArgumentError('Host is not defined'); |
| 78 | } |
| 79 | |
| 80 | return this._inFlightQueries[host.address] || 0; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns the string representation of the instance. |
| 85 | */ |
| 86 | toString() { |
| 87 | return util.format('{"hosts": %j, "openConnections": %j, "inFlightQueries": %j}', |
| 88 | this._hosts.map(function (h) { return h.address; }), this._openConnections, this._inFlightQueries); |
nothing calls this directly
no outgoing calls
no test coverage detected