Exemplo n.º 1
0
    def Process(self, request, context):
        if not isinstance(request, common_pb2.Message):
            logging.error("Received unexpected request type: %s",
                          request.__class__.__name__)
            context.set_code(grpc.StatusCode.UNKNOWN)
            return common_pb2.EmptyMessage()
        if request.destination.client_id:
            logging.error("Received message for client: %s",
                          request.destination.client_id)
            context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            return common_pb2.EmptyMessage()
        if request.destination.service_name != self._service_name:
            logging.error("Received message for unknown service: %s",
                          request.destination.service_name)
            context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            return common_pb2.EmptyMessage()

        self._process_callback(request, context)
        return common_pb2.EmptyMessage()
Exemplo n.º 2
0
 def _KeepAliveLoop(self):
   try:
     while True:
       with self._shutdown_cv:
         if self._shutdown:
           return
         self._shutdown_cv.wait(timeout=5)
         if self._shutdown:
           return
       try:
         self._stub.KeepAlive(common_pb2.EmptyMessage(), timeout=1.0)
       except grpc.RpcError as e:
         logging.warning("KeepAlive rpc failed: %s", e)
   except Exception as e:  # pylint: disable=broad-except
     logging.error("Exception in KeepAlive: %s", e)