Skip to content

Commit

Permalink
Merge pull request #180 from uber/ctor-channel
Browse files Browse the repository at this point in the history
Client can make use of subChannel passed into constructor
  • Loading branch information
jwolski2 committed Oct 2, 2015
2 parents 47901af + 1e1b4a5 commit 694c046
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 13 additions & 6 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
var safeParse = require('./lib/util.js').safeParse;
var TChannel = require('tchannel');

function RingpopClient() {
this.tchannel = new TChannel();
this.subChannel = this.tchannel.makeSubChannel({
serviceName: 'ringpop'
});
function RingpopClient(subChannel) {
this.subChannel = subChannel;
this.isChannelOwner = false;
if (!this.subChannel) {
this.tchannel = new TChannel();
this.subChannel = this.tchannel.makeSubChannel({
serviceName: 'ringpop'
});
this.isChannelOwner = true;
}
}

RingpopClient.prototype.adminConfigGet = function adminConfigGet(host, body, callback) {
Expand All @@ -50,7 +55,9 @@ RingpopClient.prototype.adminGossipTick= function adminGossipTick(host, callback
};

RingpopClient.prototype.destroy = function destroy(callback) {
this.tchannel.close(callback);
if (this.isChannelOwner) {
this.tchannel.close(callback);
}
};

/* jshint maxparams: 5 */
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var MembershipUpdateRollup = require('./lib/membership/rollup.js');
var nulls = require('./lib/nulls');
var rawHead = require('./lib/request-proxy/util.js').rawHead;
var RequestProxy = require('./lib/request-proxy/index.js');
var RingpopClient = require('./client.js');
var RingpopServer = require('./server');
var safeParse = require('./lib/util').safeParse;
var sendJoin = require('./lib/swim/join-sender.js').joinCluster;
Expand Down Expand Up @@ -218,6 +219,7 @@ RingPop.prototype.destroy = function destroy() {
};

RingPop.prototype.setupChannel = function setupChannel() {
this.client = new RingpopClient(this.channel);
this.server = new RingpopServer(this, this.channel);
};

Expand Down

0 comments on commit 694c046

Please sign in to comment.