summaryrefslogtreecommitdiff
path: root/src/mongo/shell/replsetbridge.js
blob: 405044067ad0cf7a41c105549283dc29a9500907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
ReplSetBridge = function(rst, from, to, delay) {
    var n = rst.nodes.length;

    var startPort = rst.startPort+n;
    this.port = (startPort+(from*n+to));
    this.host = rst.host+":"+this.port;

    this.dest = rst.host+":"+rst.ports[to];
    this.delay = delay || 0;
    this.start();
};

ReplSetBridge.prototype.start = function() {
    var args = ["mongobridge", "--port", this.port, "--dest", this.dest, "--delay", this.delay];
    print("ReplSetBridge starting: "+tojson(args));
    this.bridge = startMongoProgram.apply( null , args );
    print("ReplSetBridge started " + this.bridge);
};

ReplSetBridge.prototype.stop = function() {
    print("ReplSetBridge stopping: " + this.port);
    stopMongod(this.port, 9);
};

ReplSetBridge.prototype.toString = function() {
    return this.host+" -> "+this.dest;
};

/**
 * Restart the bridge with a specified delay.
 */
ReplSetBridge.prototype.setDelay = function (delay) {
    this.stop();
    this.delay = delay || 0;
    this.start();
};