A message has been received from a server

        :param client: Client that received the message
        :param userdata: User data (unused)
        :param msg: A MQTTMessage bean
331082
def __on_message(self, client, userdata, msg):
        # pylint: disable=W0613
        
        # Notify the caller, if any
        if self.on_message is not None:
            try:
                self.on_message(self, msg)
            except Exception as ex:
                _logger.exception("Error notifying MQTT listener: %s", ex)
312503
protected static void noteMessage (SpeakObject sender, Name username, UserMessage msg)
    {
        // fill in the message's time stamp if necessary
        if (msg.timestamp == 0L) {
            msg.timestamp = System.currentTimeMillis();
        }

        // Log.info("Noted that " + username + " heard " + msg + ".");

        // notify any message observers
        _messageOp.init(sender, username, msg);
        _messageObs.apply(_messageOp);
    }
839657
def message_user(self, username, domain, subject, message):
        """"""

        kwargs = {
            'body': message,
            'from': domain,
            'to': '%s@%s' % (username, domain),
        }

        if self.api_version <= (14, 7):
            # TODO: it's unclear when send_message was introduced
            command = 'send_message_chat'
        else:
            command = 'send_message'
            kwargs['subject'] = subject
            kwargs['type'] = 'normal'
        result = self.rpc(command, **kwargs)

        if result['res'] == 0:
            return
        else:
            raise BackendError(result.get('text', 'Unknown Error'))
1250696
def new_messages_handler(stream):
    
    # TODO: handle no user found exception
    while True:
        packet = yield from stream.get()
        session_id = packet.get('session_key')
        msg = packet.get('message')
        username_opponent = packet.get('username')
        if session_id and msg and username_opponent:
            user_owner = get_user_from_session(session_id)
            if user_owner:
                user_opponent = get_user_model().objects.get(username=username_opponent)
                dialog = get_dialogs_with_user(user_owner, user_opponent)
                if len(dialog) > 0:
                    # Save the message
                    msg = models.Message.objects.create(
                        dialog=dialog[0],
                        sender=user_owner,
                        text=packet['message'],
                        read=False
                    )
                    packet['created'] = msg.get_formatted_create_datetime()
                    packet['sender_name'] = msg.sender.username
                    packet['message_id'] = msg.id

                    # Send the message
                    connections = []
                    # Find socket of the user which sent the message
                    if (user_owner.username, user_opponent.username) in ws_connections:
                        connections.append(ws_connections[(user_owner.username, user_opponent.username)])
                    # Find socket of the opponent
                    if (user_opponent.username, user_owner.username) in ws_connections:
                        connections.append(ws_connections[(user_opponent.username, user_owner.username)])
                    else:
                        # Find sockets of people who the opponent is talking with
                        opponent_connections = list(filter(lambda x: x[0] == user_opponent.username, ws_connections))
                        opponent_connections_sockets = [ws_connections[i] for i in opponent_connections]
                        connections.extend(opponent_connections_sockets)

                    yield from fanout_message(connections, packet)
                else:
                    pass  # no dialog found
            else:
                pass  # no user_owner
        else:
            pass
175742
def new_reply(cls, thread, user, content):
        
        msg = cls.objects.create(thread=thread, sender=user, content=content)
        thread.userthread_set.exclude(user=user).update(deleted=False, unread=True)
        thread.userthread_set.filter(user=user).update(deleted=False, unread=False)
        message_sent.send(sender=cls, message=msg, thread=thread, reply=True)
        return msg
450196
def received_message(self, data):
        """"""
        data = ejson.loads(str(data))
        if not data.get('msg'):
            return

        elif data['msg'] == 'failed':
            self._ddp_version_index += 1
            self._retry_new_version = data.get('version', True)
            self.emit('failed', data)

        elif data['msg'] == 'connected':
            self._session = data.get('session')
            if self._is_reconnecting:
                self.ddpsocket._debug_log("* RECONNECTED")
                self.emit('reconnected')
                self._is_reconnecting = False
            else:
                self.ddpsocket._debug_log("* CONNECTED")
                self.emit('connected')
                self._retry_new_version = False

        # method result
        elif data['msg'] == 'result':
            # call the optional callback
            callback = self._callbacks.get(data['id'])
            if callback:
                callback(data.get('error'), data.get('result'))
                self._callbacks.pop(data['id'])

        # missing subscription
        elif data['msg'] == 'nosub':
            callback = self._callbacks.get(data['id'])
            if callback:
                callback(data.get('error'), data['id'])
                self._callbacks.pop(data['id'])

        # document added to collection
        elif data['msg'] == 'added':
            self.emit('added', data['collection'],
                      data['id'], data.get('fields', {}))

        # document changed in collection
        elif data['msg'] == 'changed':
            self.emit('changed', data['collection'], data['id'],
                       data.get('fields', {}), data.get('cleared', {}))

        # document removed from collection
        elif data['msg'] == 'removed':
            self.emit('removed', data['collection'], data['id'])

        # subcription ready
        elif data['msg'] == 'ready':
            for sub_id in data.get('subs', []):
                callback = self._callbacks.get(sub_id)
                if callback:
                    callback(data.get('error'), sub_id)
                    self._callbacks.pop(sub_id)

        elif data['msg'] == 'ping':
            msg = {'msg': 'pong'}
            id = data.get('id')
            if id is not None:
                msg['id'] = id
            self.ddpsocket.send(msg)

        else:
            pass
399038
def receive_message(msg)
      response = Oj.load(msg.data)
      # this check is important in case a request timeout and we make new ones after
      if response['requestId'] == @request_id
        if @response.nil?
          @response = response
        else
          @response['result']['data'].concat response['result']['data']
          @response['result']['meta'].merge! response['result']['meta']
          @response['status'] = response['status']
        end
      end
    end
171879
def message(self, message, thread_id=None):
        
        return_value = helpers.Messager(self._session).send(
            self.username, message, self.authcode, thread_id
        )
        self.refresh(reload=False)
        return return_value
1317120
def on_message(self, client, userdata, msg):
        '''
        
        '''
        if msg.topic == 'serial_device/refresh_comports':
            self.refresh_comports()
            return

        match = CRE_MANAGER.match(msg.topic)
        if match is None:
            logger.debug('Topic NOT matched: `%s`', msg.topic)
        else:
            logger.debug('Topic matched: `%s`', msg.topic)
            # Message topic matches command.  Handle request.
            command = match.group('command')
            port = match.group('port')

            #     serial_device/<port>/send   # Bytes to send
            if command == 'send':
                self._serial_send(port, msg.payload)
            elif command == 'connect':
                # serial_device/<port>/connect  # Request connection
                try:
                    request = json.loads(msg.payload)
                except ValueError as exception:
                    logger.error('Error decoding "%s (%s)" request: %s',
                                 command, port, exception)
                    return
                self._serial_connect(port, request)
            elif command == 'close':
                self._serial_close(port)
1137171
def on_pubmsg(self, connection, event):
        
        sender = self.get_nick(event.source)
        channel = event.target
        message = event.arguments[0]

        self.handle_message(connection, sender, channel, message)
1016023
def from_raw_message(cls, rawmessage):
        """"""
        empty = cls.create_empty(0x00)
        userdata_dict = cls.normalize(empty, rawmessage)
        return Userdata(userdata_dict)
1269708
def on_message_received(self, msg):
        
        if self.is_stopped:
            raise RuntimeError("reader has already been stopped")
        else:
            self.buffer.put(msg)
1129244
def _on_message(self, socket, message):
        
        data = json.loads(message)
        message_type = None
        identifier = None
        subscription = None

        if 'type' in data:
            message_type = data['type']

        if 'identifier' in data:
            identifier = json.loads(data['identifier'])

        if identifier is not None:
            subscription = self.find_subscription(identifier)

        if subscription is not None:
            subscription.received(data)
        elif message_type == 'welcome':
            self.logger.debug('Welcome message received.')

            for subscription in self.subscriptions.values():
                if subscription.state == 'connection_pending':
                    subscription.create()

        elif message_type == 'ping':
            if self.log_ping:
                self.logger.debug('Ping received.')
        else:
            self.logger.warning('Message not supported. (Message: {})'.format(message))
976737
def read_message_handler(stream):
    
    while True:
        packet = yield from stream.get()
        session_id = packet.get('session_key')
        user_opponent = packet.get('username')
        message_id = packet.get('message_id')
        if session_id and user_opponent and message_id is not None:
            user_owner = get_user_from_session(session_id)
            if user_owner:
                message = models.Message.objects.filter(id=message_id).first()
                if message:
                    message.read = True
                    message.save()
                    logger.debug('Message ' + str(message_id) + ' is now read')
                    opponent_socket = ws_connections.get((user_opponent, user_owner.username))
                    if opponent_socket:
                        yield from target_message(opponent_socket,
                                                  {'type': 'opponent-read-message',
                                                   'username': user_opponent, 'message_id': message_id})
                else:
                    pass  # message not found
            else:
                pass  # invalid session id
        else:
            pass
793827
def message(message)
      reqdata = reqdata()
      reqdata.merge!({
        :nick => @endpoint[:nick],
        :type => "chat",
        :style => "",
        :timestamp => Time.now.to_f * 1000
      })
      reqdata.merge!(message)
      httpost('/messages', reqdata)
    end
1004679
def _on_msg(self, msg):
        """"""
        data = msg['content']['data']

        # If the message is a call invoke, run the function and send
        # the results.
        if 'callback' in data:
            guid = data['callback']
            callback = callback_registry[guid]
            args = data['arguments']
            args = [self.deserialize(a) for a in args]
            index = data['index']

            results = callback(*args)
            return self.serialize(self._send('return', index=index, results=results))

        # The message is not a call invoke, it must be an object
        # that is a response to a Python request.
        else:
            index = data['index']
            immutable = data['immutable']
            value = data['value']
            if index in self._callbacks:
                self._callbacks[index].resolve({
                    'immutable': immutable,
                    'value': value
                })
                del self._callbacks[index]
820687
public void receive(Message msg) {
        Request req=null;

        if(msg == null || msg.getLength() == 0)
            return;
        try {
            req=msg.getObject();

            String fqn=req.fqn;
            switch(req.type) {
                case Request.PUT:
                    if(req.key != null && req.value != null)
                        _put(fqn, req.key, req.value);
                    else
                        _put(fqn, req.data);
                    break;
                case Request.REMOVE:
                    if(req.key != null)
                        _remove(fqn, req.key);
                    else
                        _remove(fqn);
                    break;
                default:
                    if(log.isErrorEnabled()) log.error("type " + req.type + " unknown");
                    break;
            }
        }
        catch(Exception ex) {
            if(log.isErrorEnabled()) log.error("failed unmarshalling request: " + ex);
        }
    }