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?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to