Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
lint/style fixes
  • Loading branch information
Mark Cavage committed Aug 14, 2012
1 parent 4d5bca9 commit 944bbcd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
37 changes: 17 additions & 20 deletions lib/generic-election.js
Expand Up @@ -39,14 +39,14 @@ util.inherits(Election, EventEmitter);
* where context is either the nodes in the election if leader, or the leader if
* not leader.
*/
Election.prototype.isLeader = function isLeader(watch, cached, callback) {
Election.prototype.isLeader = function isLeader(doWatch, cached, callback) {
assert.func(callback, 'callback');
var self = this;
var log = self.log;

log.trace({
callback: callback,
watch: watch,
watch: doWatch,
parent: self.parent,
znode: self.znode
}, 'election.isLeader: entered');
Expand Down Expand Up @@ -79,15 +79,15 @@ Election.prototype.isLeader = function isLeader(watch, cached, callback) {
leaderIndex: leaderIndex,
znode: self.znode
}, 'election.isLeader: not leader');
if (watch) {
if (doWatch) {
log.trace('election.isLeader: ' +
' watching leader');
self.watch(function (err) {
if (err) {
callback(err);
self.watch(function (err2) {
if (err2) {
callback(err2);
} else {
callback(null, false,
self.leader);
self.leader);
}
});
} else {
Expand All @@ -96,6 +96,7 @@ Election.prototype.isLeader = function isLeader(watch, cached, callback) {
}
}
});
return (undefined);
};

Election.prototype.vote = function vote(callback) {
Expand All @@ -113,7 +114,7 @@ Election.prototype.vote = function vote(callback) {
var tasks = [
function mkdir(_, cb) {
log.trace({
parent: self.parent,
parent: self.parent
}, 'mkdir -p');
client.mkdirp(self.parent, cb);
},
Expand All @@ -127,7 +128,7 @@ Election.prototype.vote = function vote(callback) {
_path = self.parent + '/' +
self.pathPrefix + '-';
} else {
var _path = self.parent + '/-';
_path = self.parent + '/-';
}
client.create(_path, opts, function (err, p) {
if (err) {
Expand All @@ -149,9 +150,7 @@ Election.prototype.vote = function vote(callback) {
});
},
function _isLeader(_, cb) {
self.isLeader(true, false,
function (err, isLeader, context)
{
self.isLeader(true, false, function (err, isl, ctx) {
if (err) {
log.trace({
parent: self.parent,
Expand All @@ -164,7 +163,7 @@ Election.prototype.vote = function vote(callback) {
path: self.path,
znode: self.znode,
isLeader: self.amLeader,
context: context
context: ctx
}, 'election.vote: determined leader');
cb();
}
Expand Down Expand Up @@ -244,19 +243,17 @@ Election.prototype.watch = function watch(callback) {
leader: self.leader
}, 'election.watch: delete event');
watcher.stop();
self.isLeader(true, false,
function (err, isLeader, context)
{
if (err) {
self.isLeader(true, false, function (err2, isl, ctx) {
if (err2) {
log.trace({
path: self.path,
parent: self.parent,
znode: self.znode,
err: err
err: err2
}, 'election.watch: error event');
self.emit('error', err);
}
if (isLeader) {
if (isl) {
log.trace({
parent: self.parent,
znode: self.znode,
Expand Down Expand Up @@ -402,4 +399,4 @@ function _getLeader(self, callback) {
});
}
});
};
}
12 changes: 8 additions & 4 deletions lib/index.js
Expand Up @@ -40,14 +40,18 @@ module.exports = {
pollInterval: options.pollInterval || 0
};
if (options.servers) {
options.servers.forEach(function(server) {
if(!server.host) {
// handle cases where we receive a connection string
options.servers.forEach(function (server) {
if (!server.host) {
// handle cases where we receive a
// connection string:
// "localhost:2181"
server = server.split(':');
var port = 2181;
if (server[1])
port = parseInt(server[1], 10);
opts.servers.push({
host: server[0],
port: server[1] && parseInt(server[1], 10) || 2181
port: port
});
} else {
opts.servers.push(server);
Expand Down
4 changes: 2 additions & 2 deletions test/client.test.js
Expand Up @@ -28,8 +28,8 @@ var connectTimeout;

before(function (callback) {
try {
connectTimeout = setTimeout(function() {
console.error('Could not connect to a ZK instance, did you start one?');
connectTimeout = setTimeout(function () {
console.error('Could not connect to a ZK instance');
}, 1500);

ZK = zk.createClient({
Expand Down
4 changes: 2 additions & 2 deletions test/generic-election.test.js
Expand Up @@ -450,7 +450,7 @@ function _resetState(callback) {
return callback(err);
});

function resetZK(callback) {
function resetZK(_callback) {
try {
ZK = zk.createClient({
log: LOG,
Expand All @@ -474,7 +474,7 @@ function _resetState(callback) {
process.exit(1);
}

callback();
_callback();
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/server-string.test.js
Expand Up @@ -28,8 +28,8 @@ var connectTimeout;

before(function (callback) {
try {
connectTimeout = setTimeout(function() {
console.error('Could not connect to a ZK instance, did you start one?');
connectTimeout = setTimeout(function () {
console.error('Could not connect to a ZK instance');
}, 1500);

ZK = zk.createClient({
Expand Down

0 comments on commit 944bbcd

Please sign in to comment.