'Processes a queue of messages as passed from the client.
We basically dispatch all the GrrMessages in the queue to the task scheduler
for backend processing. We then retrieve from the TS the messages destined
for this client.
Args:
request_comms: A ClientCommunication rdfvalue with messages sent by the
client. source should be set to the client CN.
response_comms: A ClientCommunication rdfvalue of jobs destined to this
client.
Returns:
tuple of (source, message_count) where message_count is the number of
messages received from the client with common name source.'

@stats.Counted('grr_frontendserver_handle_num')
@stats.Timed('grr_frontendserver_handle_time')
def HandleMessageBundles(self, request_comms, response_comms):

    (messages, source, timestamp) = self._communicator.DecodeMessages(request_comms)
    now = time.time()
    if messages:
        self.ReceiveMessages(source, messages)
    required_count = max(0, (self.max_queue_size - request_comms.queue_size))
    tasks = []
    message_list = rdf_flows.MessageList()
    if ((time.time() - now) < 10):
        tasks = self.DrainTaskSchedulerQueueForClient(source, required_count)
        message_list.job = tasks
    try:
        self._communicator.EncodeMessages(message_list, response_comms, destination=str(source), timestamp=timestamp, api_version=request_comms.api_version)
    except communicator.UnknownClientCert:
        queue_manager.QueueManager(token=self.token).Schedule(tasks)
        raise
    return (source, len(messages))
