From fe11579905f454e14af876f87e3c208431196bee Mon Sep 17 00:00:00 2001 From: David Luu Date: Sun, 8 May 2016 15:34:48 -0700 Subject: [PATCH] backport change from master: add convenience methods for checking tuple type in node.js library --- .../src/main/resources/resources/storm.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/storm-multilang/javascript/src/main/resources/resources/storm.js b/storm-multilang/javascript/src/main/resources/resources/storm.js index dc6efc13863..c8462ba24fd 100755 --- a/storm-multilang/javascript/src/main/resources/resources/storm.js +++ b/storm-multilang/javascript/src/main/resources/resources/storm.js @@ -199,7 +199,7 @@ Storm.prototype.emitDirect = function(commandDetails) { /** * Initialize storm component according to the configuration received. - * @param conf configuration object accrding to storm protocol. + * @param conf configuration object according to storm protocol. * @param context context object according to storm protocol. * @param done callback. Call this method when finished initializing. */ @@ -221,10 +221,18 @@ function Tuple(id, component, stream, task, values) { this.values = values; } +Tuple.prototype.isTickTuple = function(){ + return this.task === -1 && this.stream === "__tick"; +} + +Tuple.prototype.isHeartbeatTuple = function(){ + return this.task === -1 && this.stream === "__heartbeat"; +} + /** * Base class for storm bolt. * To create a bolt implement 'process' method. - * You may also implement initialize method to + * You may also implement initialize method too */ function BasicBolt() { Storm.call(this); @@ -262,7 +270,7 @@ BasicBolt.prototype.handleNewCommand = function(command) { var self = this; var tup = new Tuple(command["id"], command["comp"], command["stream"], command["task"], command["tuple"]); - if (tup.task === -1 && tup.stream === "__heartbeat") { + if (tup.isHeartbeatTuple()) { self.sync(); return; } @@ -293,7 +301,6 @@ BasicBolt.prototype.fail = function(tup, err) { this.sendMsgToParent({"command": "fail", "id": tup.id}); } - /** * Base class for storm spout. * To create a spout implement the following methods: nextTuple, ack and fail (nextTuple - mandatory, ack and fail @@ -370,4 +377,4 @@ Spout.prototype.__emit = function(commandDetails) { } module.exports.BasicBolt = BasicBolt; -module.exports.Spout = Spout; \ No newline at end of file +module.exports.Spout = Spout;