classClusterClientextendsBase { // ... async [init]() { const name = this.options.name; const port = this.options.port; let server; if (this.options.isLeader === true) { server = awaitClusterServer.create(name, port); if (!server) { thrownewError(`create "${name}" leader failed, the port:${port} is occupied by other`); } } elseif (this.options.isLeader === false) { // wait for leader active awaitClusterServer.waitFor(port, this.options.maxWaitTime); } else { debug('[ClusterClient:%s] init cluster client, try to seize the leader on port:%d', name, port); server = awaitClusterServer.create(name, port); }
if (server) { this[innerClient] = newLeader(Object.assign({ server }, this.options)); debug('[ClusterClient:%s] has seized port %d, and serves as leader client.', name, port); } else { this[innerClient] = newFollower(this.options); debug('[ClusterClient:%s] gives up seizing port %d, and serves as follower client.', name, port); } // ... } }
Comments