MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / setDistance

Method setDistance

lib/host.js:245–275  ·  view source on GitHub ↗

* Sets the distance of the host relative to the client using the load balancing policy. * @param {Number} distance * @internal * @ignore

(distance)

Source from the content-addressed store, hash-verified

243 * @ignore
244 */
245 setDistance(distance) {
246 const previousDistance = this._distance;
247 this._distance = distance || types.distance.local;
248 if (this.options.pooling.coreConnectionsPerHost) {
249 this.pool.coreConnectionsLength = this.options.pooling.coreConnectionsPerHost[this._distance] || 0;
250 }
251 else {
252 this.pool.coreConnectionsLength = 1;
253 }
254 if (this._distance === previousDistance) {
255 return this._distance;
256 }
257 if (this._healthResponseCountTimer) {
258 clearInterval(this._healthResponseCountTimer);
259 }
260 if (this._distance === types.distance.ignored) {
261 // this host was local/remote and now must be ignored
262 this.emit('ignore');
263 this.pool.drainAndShutdown();
264 }
265 else {
266 if (!this.isUp()) {
267 this.checkIsUp();
268 }
269 // Reset the health check timer
270 this._healthResponseCountTimer = setInterval(() => {
271 this._healthResponseCounter = this.pool.getAndResetResponseCounter();
272 }, healthResponseCountInterval);
273 }
274 return this._distance;
275 }
276
277 /**
278 * Changes the protocol version of a given host

Callers 3

getDistanceMethod · 0.80
host-tests.jsFile · 0.80

Calls 4

isUpMethod · 0.95
checkIsUpMethod · 0.95
drainAndShutdownMethod · 0.80

Tested by

no test coverage detected