(server: Server, options: MonitorOptions)
| 102 | private rttSampler: RTTSampler; |
| 103 | |
| 104 | constructor(server: Server, options: MonitorOptions) { |
| 105 | super(); |
| 106 | this.on('error', noop); |
| 107 | |
| 108 | this.server = server; |
| 109 | this.connection = null; |
| 110 | this.cancellationToken = new CancellationToken(); |
| 111 | this.cancellationToken.setMaxListeners(Infinity); |
| 112 | this.monitorId = undefined; |
| 113 | this.s = { |
| 114 | state: STATE_CLOSED |
| 115 | }; |
| 116 | this.address = server.description.address; |
| 117 | this.options = Object.freeze({ |
| 118 | connectTimeoutMS: options.connectTimeoutMS ?? 10000, |
| 119 | heartbeatFrequencyMS: options.heartbeatFrequencyMS ?? 10000, |
| 120 | minHeartbeatFrequencyMS: options.minHeartbeatFrequencyMS ?? 500, |
| 121 | serverMonitoringMode: options.serverMonitoringMode |
| 122 | }); |
| 123 | this.isRunningInFaasEnv = getFAASEnv() != null; |
| 124 | this.mongoLogger = this.server.topology.client?.mongoLogger; |
| 125 | this.rttSampler = new RTTSampler(10); |
| 126 | |
| 127 | const cancellationToken = this.cancellationToken; |
| 128 | // TODO: refactor this to pull it directly from the pool, requires new ConnectionPool integration |
| 129 | const connectOptions = { |
| 130 | id: '<monitor>' as const, |
| 131 | generation: server.pool.generation, |
| 132 | cancellationToken, |
| 133 | hostAddress: server.description.hostAddress, |
| 134 | ...options, |
| 135 | // force BSON serialization options |
| 136 | raw: false, |
| 137 | useBigInt64: false, |
| 138 | promoteLongs: true, |
| 139 | promoteValues: true, |
| 140 | promoteBuffers: true |
| 141 | }; |
| 142 | |
| 143 | // ensure no authentication is used for monitoring |
| 144 | delete connectOptions.credentials; |
| 145 | if (connectOptions.autoEncrypter) { |
| 146 | delete connectOptions.autoEncrypter; |
| 147 | } |
| 148 | |
| 149 | this.connectOptions = Object.freeze(connectOptions); |
| 150 | } |
| 151 | |
| 152 | connect(): void { |
| 153 | if (this.s.state !== STATE_CLOSED) { |
nothing calls this directly
no test coverage detected