[
https://issues.apache.org/jira/browse/STORM-386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14115398#comment-14115398
]
ASF GitHub Bot commented on STORM-386:
--------------------------------------
Github user d2r commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/177#discussion_r16906692
--- Diff: examples/storm-starter/multilang/resources/storm.js ---
@@ -0,0 +1,348 @@
+/**
+ * Base classes in node-js for storm Bolt and Spout.
+ * Implements the storm multilang protocol for nodejs.
+ */
+
+
+var fs = require('fs');
+
+function Storm() {
+ this.messagePart = "";
+ this.taskIdsCallbacks = [];
+ this.isFirstMessage = true;
+ this.separator = '\nend\n';
+}
+
+Storm.prototype.sendMsgToParent = function(msg) {
+ var str = JSON.stringify(msg);
+ process.stdout.write(str + this.separator);
+}
+
+Storm.prototype.sync = function() {
+ this.sendMsgToParent({"command":"sync"});
+}
+
+Storm.prototype.sendPid = function(heartbeatdir) {
+ var pid = process.pid;
+ fs.closeSync(fs.openSync(heartbeatdir + "/" + pid, "w"));
+ this.sendMsgToParent({"pid": pid})
+}
+
+Storm.prototype.log = function(msg) {
+ this.sendMsgToParent({"command": "log", "msg": msg});
+}
+
+Storm.prototype.initSetupInfo = function(setupInfo) {
+ var self = this;
+ var callback = function() {
+ self.sendPid(setupInfo['pidDir']);
+ }
+ this.initialize(setupInfo['conf'], setupInfo['context'], callback);
+}
+
+Storm.prototype.startReadingInput = function() {
+ var self = this;
+ process.stdin.on('readable', function() {
+ var chunk = process.stdin.read();
+ var messages = self.handleNewChunk(chunk);
+ messages.forEach(function(message) {
+ self.handleNewMessage(message);
+ })
+
+ });
+}
+
+/**
+ * receives a new string chunk and returns a list of new messages with the
separator removed
+ * stores state in this.messagePart
+ * @param chunk
+ */
+Storm.prototype.handleNewChunk = function(chunk) {
+ //invariant: this.messagePart has no separator otherwise we would have
parsed it already
+ var messages = [];
+ if (chunk && chunk.length !== 0) {
+ //"{}".split("\nend\n") ==> ['{}']
+ //"\nend\n".split("\nend\n") ==> ['' , '']
+ //"{}\nend\n".split("\nend\n") ==> ['{}', '']
+ //"\nend\n{}".split("\nend\n") ==> ['' , '{}']
+ // "{}\nend\n{}".split("\nend\n") ==> ['{}', '{}' ]
--- End diff --
Are these comments still needed?
> Development of multilang protocol in nodejs
> -------------------------------------------
>
> Key: STORM-386
> URL: https://issues.apache.org/jira/browse/STORM-386
> Project: Apache Storm (Incubating)
> Issue Type: New Feature
> Environment: nodejs
> Reporter: Anya Tchernishov
>
> Support nodejs multilang protocol.
> Design considerations:
> - Emit will receive an object (like args and kwargs in python) and a callback
> that is called when task ids list is received.
> self.emit({tuple: [word]}, function(taskIds) {
> self.log(word + ' sent to task ids - ' + taskIds);
> });
> - The following methods will received done method that must be invoked on
> completion (same pattern used by the mocha test framework for async unit
> tests).
> - Internal implementation of emit uses Process.stdout.write without a
> callback since nodejs streams maintain FIFO order (so far, we have not found
> a need for providing a callback).
>
--
This message was sent by Atlassian JIRA
(v6.2#6252)