Handle incoming message

@param {string} msg JSON message to parse

@return {JRPC} This instance, for chaining
767162
function receive(msg) {
  var requests = [];
  var responses = [];

  if (!this.active) {
    return this;
  }

  // If we got JSON, parse it
  if (typeof msg === 'string') {
    try {
      msg = JSON.parse(msg);
    } catch (e) {
      // The specification doesn't force us to respond in error, ignoring
      return this;
    }
  }

  // If we get a standard single-type batch, dispatch it
  if (msg.constructor === Array) {
    if (msg.length === 0) {
      return this;
    }
    // Hint of request batch
    if (typeof msg[0].method === 'string') {
      requests = msg;
    } else {
      responses = msg;
    }
  } else if (typeof msg === 'object') {
    // Could we be a 'dual-batch' extended message?
    if (
      typeof msg.requests !== 'undefined'
      && typeof msg.responses !== 'undefined'
    ) {
      requests = msg.requests;
      responses = msg.responses;
    } else if (typeof msg.method === 'string') {
      // We're a single request
      requests.push(msg);
    } else {
      // We must be a single response
      responses.push(msg);
    }
  }

  responses.forEach(deliverResponse.bind(this));
  requests.forEach(serveRequest.bind(this));
  return this;
}
149316
function onMessage(message) {
    if (!channel._wsConn) return
    if (message.type != "utf8") return

    message = JSON.parse(message.utf8Data)
    DEBUGMSG("onMessage", utils.JL(message))

    channel.emit("message", message)
  }
141585
function handleChat(payload) {
        if (!payload.message) {
            return Promise.reject(new Error('Event payload did not include chat message'));
        }
        const message = ChatRoom.Message.parse(payload.message);

        forum.emit('chatMessage', message);
        const ids = {
            post: -1,
            topic: -1,
            user: message.from.id,
            pm: message.room,
            chat: message.id
        };
        return forum.Commands.get(ids, message.content, (content) => message.reply(content))
            .then((command) => command.execute());
    }
1043230
def handle_message(message)
      begin
        message = decode_message message
      rescue InvalidMessageError => ex
        Logger.crash("couldn't decode message", ex)
        return
      end

      begin
        message.dispatch
      rescue => ex
        Logger.crash("message dispatch failed", ex)
      end
    end
366873
function _parseMessage() {
    let message = [].slice.call(arguments).join("|");
    try {
        message = (typeof message === "string") ? message : JSON.stringify(message);
    } catch(e) {
        logger.error(e.stack);
    }

    return message;
}
984003
@Override
    public void handleMessage(Message msg) {
        if (msg.what == ASYNC) {
            mAsyncDispatcher.dispatch();
        } else if (msg.what == SYNC) {
            mSyncDispatcher.dispatch();
        } else super.handleMessage(msg);
    }
668938
function (msgStr) {
            var msg;
            try {
                msg = JSON.parse(msgStr);
            } catch (e) {
                console.log("[Brackets LiveDev] Malformed message received: ", msgStr);
                return;
            }
            // delegates handling/routing to MessageBroker.
            MessageBroker.trigger(msg);
        }
516823
public static function parse(string $msg): Message
    {
        $obj = new self;
        $parts = explode("\r\n", $msg);
        $obj->body = MessageBody::parse(array_pop($parts));
        foreach ($parts as $line) {
            if ($line) {
                $pair = explode(': ', $line);
                $obj->headers[$pair[0]] = $pair[1];
            }
        }
        return $obj;
    }
1112723
function(node, msg) {
        if (node.complete === "complete") {
            return msg;
        }
        try {
            return (node.prop||"payload").split(".").reduce(function (obj, i) {
                return obj[i];
            }, msg);
        } catch (err) {
            return; // undefined
        }
    }
1356778
def handle_request(message, notification=false, connection={})
    # get client for the specified connection
    # TODO should grap port/ip immediately on connection and use that
    client_port,client_ip = client_for(connection)

    msg = notification ?
      Messages::Notification.new(:message => message,
                                 :headers => @message_headers) :
           Messages::Request.new(:message => message,
                                 :headers => @message_headers)

    callback = NodeCallback.new(:node       => self,
                                :connection => connection)

    result = @dispatcher.dispatch(:rjr_method      => msg.jr_method,
                                  :rjr_method_args => msg.jr_args,
                                  :rjr_headers     => msg.headers,
                                  :rjr_client_ip   => client_ip,
                                  :rjr_client_port => client_port,
                                  :rjr_node        => self,
                                  :rjr_node_id     => node_id,
                                  :rjr_node_type   => self.node_type,
                                  :rjr_callback    => callback)

    unless notification
      response = Messages::Response.new(:id      => msg.msg_id,
                                        :result  => result,
                                        :headers => msg.headers,
                                        :request => msg)
      self.send_msg(response.to_s, connection)
      return response
    end

    nil
  end
1065819
public void setReason(String msg) {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"setReason", " message --> " + msg,"["+this+"]");
        }
        _response.setReason(msg);
    }
270025
function messageHandler(msg, rinfo) {
  var msgStr = msg.toString();

  log.verbose(msgStr + ' <from: ' + rinfo.address + (rinfo.port ? ':' + rinfo.port : '') + '>');

  if (msg.length < 2) {
    return;
  }

  try {
    msg = JSON.parse(msgStr);
  } catch (e) {
    log.debug(e.stack || e.message || e);
    return;
  }

  if (!_.isPlainObject(msg)) {
    return;
  }

  // check for health check request
  if (msg.healthCheck) {
    // respond to health check and exit function
    var resp = JSON.stringify({status: (this.dropEvents ? 'backlogged' : 'ok')});

    try {
      this.server.send(resp, 0, resp.length, rinfo.port, rinfo.address, function (err) {
        if (err) {
          log.debug(err.stack || err.message || err);
        }
      });
    } catch (err) {
      log.debug(err.stack || err.message || err);
    }

    return;
  }

  if (_.isUndefined(msg.routingKey) || !_.isString(msg.routingKey) || !msg.routingKey) {
    return;
  }

  // remove illegal characters from the routing key
  msg.routingKey = msg.routingKey.replace(/[^-\.\w]/g, '');

  if (!msg.routingKey) {
    return;
  }

  if (this.dropEvents) {
    // track drop stats
    if (_.isFunction(process.send)) {
      try {
        process.send({event: 'updateEventDropStats', data: msg});
      } catch (err) {
        log.debug(err.stack || err.message || err);
      }
    }

    // last ditch effort to process event
    // hope another eventsd server is not backlogged
    if (process.env.SZ_EVENTSD_HOST && process.env.SZ_EVENTSD_PORT) {
      log.verbose('resending event to eventsd');

      try {
        var sock = new dgram.createSocket('udp4');
        var message = JSON.stringify(msg);

        sock.send(message, 0, message.length, process.env.SZ_EVENTSD_PORT, process.env.SZ_EVENTSD_HOST, function (err) {
          if (err) {
            log.verbose(err.stack || err.message || err);
          }
        });
      } catch (err) {
        log.verbose(err.stack || err.message || err);
      }
    }

    return;
  }

  // track event stats
  if (_.isFunction(process.send)) {
    try {
      process.send({event: 'updateEventStats', data: msg});
    } catch (err) {
      log.debug(err.stack || err.message || err);
    }
  }

  // publish to firehose
  this.publisher.publish(msg, {contentType: 'application/json'}, msg.routingKey);
}
848670
function (msg) {
            var msgHandlers;
            if (!msg.method) {
                // no message type, ignoring it
                // TODO: should we trigger a generic event?
                console.log("[Brackets LiveDev] Received message without method.");
                return;
            }
            // get handlers for msg.method
            msgHandlers = this.handlers[msg.method];

            if (msgHandlers && msgHandlers.length > 0) {
                // invoke handlers with the received message
                msgHandlers.forEach(function (handler) {
                    try {
                        // TODO: check which context should be used to call handlers here.
                        handler(msg);
                        return;
                    } catch (e) {
                        console.log("[Brackets LiveDev] Error executing a handler for " + msg.method);
                        console.log(e.stack);
                        return;
                    }
                });
            } else {
                // no subscribers, ignore it.
                // TODO: any other default handling? (eg. specific respond, trigger as a generic event, etc.);
                console.log("[Brackets LiveDev] No subscribers for message " + msg.method);
                return;
            }
        }
1111980
public static function parse(string $msg): Message
    {
        $decoded = json_decode($msg);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new Error(json_last_error_msg(), ErrorCode::PARSE_ERROR);
        }
        if (Notification::isNotification($decoded)) {
            $obj = new Notification($decoded->method, $decoded->params ?? null);
        } else if (Request::isRequest($decoded)) {
            $obj = new Request($decoded->id, $decoded->method, $decoded->params ?? null);
        } else if (SuccessResponse::isSuccessResponse($decoded)) {
            $obj = new SuccessResponse($decoded->id, $decoded->result);
        } else if (ErrorResponse::isErrorResponse($decoded)) {
            $obj = new ErrorResponse($decoded->id, new Error($decoded->error->message, $decoded->error->code, $decoded->error->data ?? null));
        } else {
            throw new Error('Invalid message', ErrorCode::INVALID_REQUEST);
        }
        return $obj;
    }
294647
function receive(message) {
        message = JSON.parse(message);
        _debug("receive: parsed message", message);

        if (!receivers[message.type])
            return; // ignore bad message types
        if (!hasLocal(message.to)) {
            if (typeof options.onmessagelost === "function") {
                options.onmessagelost(message);
            }
            // ignore messages to non-existant or forgotten promises
            return;
        }
        receivers[message.type](message);
    }
1005854
function(msg){
    var type = this.peek().type
      , val = undefined == this.peek().val
        ? ''
        : ' ' + this.peek().toString();
    if (val.trim() == type.trim()) val = '';
    throw new errors.ParseError(msg.replace('{peek}', '"' + type + val + '"'));
  }
705454
function render(msg, cb, ms, level) {
    if (typeof cb === 'number') {
      ms = cb;
      cb = null;
    }

    return new Message({
      parentNode: '#msgbox',
      model: {
        msg: msg,
        close: cb,
        timeout: ms || util.TOAST_DURATION,
        level: level
      }
    }).render();
  }