Beispiel #1
0
def blocking_stream_unary(end, group, method, timeout, with_call,
                          protocol_options, initial_metadata, payload_iterator,
                          pool):
    """Services in a blocking fashion a stream-in value-out servicer method."""
    rendezvous, operation_context, outcome = _invoke(end, group, method,
                                                     timeout, protocol_options,
                                                     initial_metadata, None,
                                                     False)
    if outcome is None:

        def in_pool():
            for payload in payload_iterator:
                rendezvous.consume(payload)
            rendezvous.terminate()

        pool.submit(_control.pool_wrap(in_pool, operation_context))
        if with_call:
            return next(rendezvous), rendezvous
        else:
            return next(rendezvous)
    else:
        if with_call:
            return next(rendezvous), rendezvous
        else:
            return next(rendezvous)
Beispiel #2
0
 def adaptation(operator, operation_context):
   rendezvous = _control.Rendezvous(operator, operation_context)
   outcome = operation_context.add_termination_callback(rendezvous.set_outcome)
   if outcome is None:
     pool.submit(_control.pool_wrap(in_pool, operation_context), rendezvous)
     return utilities.full_subscription(rendezvous)
   else:
     raise abandonment.Abandoned()
Beispiel #3
0
def inline_stream_stream(
    end, group, method, timeout, initial_metadata, payload_iterator, pool):
  """Services a stream-in stream-out servicer method."""
  rendezvous, operation_context, outcome = _invoke(
      end, group, method, timeout, initial_metadata, None, False)
  if outcome is None:
    def in_pool():
      for payload in payload_iterator:
        rendezvous.consume(payload)
      rendezvous.terminate()
    pool.submit(_control.pool_wrap(in_pool, operation_context))
  return rendezvous
Beispiel #4
0
 def adaptation(group, method, operator, operation_context):
   rendezvous = _control.Rendezvous(operator, operation_context)
   outcome = operation_context.add_termination_callback(rendezvous.set_outcome)
   if outcome is None:
     def in_pool():
       request_consumer = multi_method(
           group, method, rendezvous, _ServicerContext(rendezvous))
       for request in rendezvous:
         request_consumer.consume(request)
       request_consumer.terminate()
     pool.submit(_control.pool_wrap(in_pool, operation_context), rendezvous)
     return utilities.full_subscription(rendezvous)
   else:
     raise abandonment.Abandoned()
Beispiel #5
0
def future_stream_unary(
    end, group, method, timeout, protocol_options, initial_metadata,
    payload_iterator, pool):
  """Services a stream-in value-out servicer method by returning a Future."""
  rendezvous, operation_context, outcome = _invoke(
      end, group, method, timeout, protocol_options, initial_metadata, None,
      False)
  if outcome is None:
    def in_pool():
      for payload in payload_iterator:
        rendezvous.consume(payload)
      rendezvous.terminate()
    pool.submit(_control.pool_wrap(in_pool, operation_context))
  return rendezvous
Beispiel #6
0
def future_stream_unary(end, group, method, timeout, protocol_options,
                        initial_metadata, payload_iterator, pool):
    """Services a stream-in value-out servicer method by returning a Future."""
    rendezvous, operation_context, outcome = _invoke(end, group, method,
                                                     timeout, protocol_options,
                                                     initial_metadata, None,
                                                     False)
    if outcome is None:

        def in_pool():
            for payload in payload_iterator:
                rendezvous.consume(payload)
            rendezvous.terminate()

        pool.submit(_control.pool_wrap(in_pool, operation_context))
    return rendezvous
Beispiel #7
0
def _event_return_unary(
    receiver, abortion_callback, rendezvous, operation_context, outcome, pool):
  if outcome is None:
    def in_pool():
      abortion = rendezvous.add_abortion_callback(abortion_callback)
      if abortion is None:
        try:
          receiver.initial_metadata(rendezvous.initial_metadata())
          receiver.response(next(rendezvous))
          receiver.complete(
              rendezvous.terminal_metadata(), rendezvous.code(),
              rendezvous.details())
        except face.AbortionError:
          pass
      else:
        abortion_callback(abortion)
    pool.submit(_control.pool_wrap(in_pool, operation_context))
  return rendezvous
Beispiel #8
0
def blocking_stream_unary(
    end, group, method, timeout, with_call, initial_metadata, payload_iterator,
    pool):
  """Services in a blocking fashion a stream-in value-out servicer method."""
  rendezvous, operation_context, outcome = _invoke(
      end, group, method, timeout, initial_metadata, None, False)
  if outcome is None:
    def in_pool():
      for payload in payload_iterator:
        rendezvous.consume(payload)
      rendezvous.terminate()
    pool.submit(_control.pool_wrap(in_pool, operation_context))
    if with_call:
      return next(rendezvous), rendezvous
    else:
      return next(rendezvous)
  else:
    if with_call:
      return next(rendezvous), rendezvous
    else:
      return next(rendezvous)