def ReceiveMessages(self, client_id, messages):
    """Receives and processes the messages from the source.

    For each message we update the request object, and place the
    response in that request's queue. If the request is complete, we
    send a message to the worker.

    Args:
      client_id: The client which sent the messages.
      messages: A list of GrrMessage RDFValues.
    """
    now = time.time()
    with queue_manager.QueueManager(
        token=self.token, store=self.data_store) as manager:
      sessions_handled = []
      for session_id, msgs in utils.GroupBy(
          messages, operator.attrgetter("session_id")).iteritems():

        # Remove and handle messages to WellKnownFlows
        unprocessed_msgs = self.HandleWellKnownFlows(msgs)

        if not unprocessed_msgs: continue

        # Keep track of all the flows we handled in this request.
        sessions_handled.append(session_id)

        for msg in unprocessed_msgs:
          manager.QueueResponse(session_id, msg)

        for msg in unprocessed_msgs:
          # Messages for well known flows should notify even though they don't
          # have a status.
          if msg.request_id == 0:
            manager.QueueNotification(session_id=msg.session_id,
                                      priority=msg.priority)
            # Those messages are all the same, one notification is enough.
            break
          elif msg.type == rdf_flows.GrrMessage.Type.STATUS:
            # If we receive a status message from the client it means the client
            # has finished processing this request. We therefore can de-queue it
            # from the client queue.
            manager.DeQueueClientRequest(client_id, msg.task_id)
            manager.QueueNotification(session_id=msg.session_id,
                                      priority=msg.priority,
                                      last_status=msg.request_id)

            stat = rdf_flows.GrrStatus(msg.payload)
            if stat.status == rdf_flows.GrrStatus.ReturnedStatus.CLIENT_KILLED:
              # A client crashed while performing an action, fire an event.
              Events.PublishEvent("ClientCrash", rdf_flows.GrrMessage(msg),
                                  token=self.token)

    logging.debug("Received %s messages in %s sec", len(messages),
                  time.time() - now)
dataset/ETHPy150Open google/grr/grr/lib/flow.py/FrontEndServer.ReceiveMessages/original