Esempio n. 1
0
    def set_up_implementation(self, name, methods,
                              inline_value_in_value_out_methods,
                              inline_value_in_stream_out_methods,
                              inline_stream_in_value_out_methods,
                              inline_stream_in_stream_out_methods,
                              event_value_in_value_out_methods,
                              event_value_in_stream_out_methods,
                              event_stream_in_value_out_methods,
                              event_stream_in_stream_out_methods,
                              multi_method):
        servicer_pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)
        stub_pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

        servicer = implementations.servicer(
            servicer_pool,
            inline_value_in_value_out_methods=inline_value_in_value_out_methods,
            inline_value_in_stream_out_methods=
            inline_value_in_stream_out_methods,
            inline_stream_in_value_out_methods=
            inline_stream_in_value_out_methods,
            inline_stream_in_stream_out_methods=
            inline_stream_in_stream_out_methods,
            event_value_in_value_out_methods=event_value_in_value_out_methods,
            event_value_in_stream_out_methods=event_value_in_stream_out_methods,
            event_stream_in_value_out_methods=event_stream_in_value_out_methods,
            event_stream_in_stream_out_methods=
            event_stream_in_stream_out_methods,
            multi_method=multi_method)

        linked_pair = base_util.linked_pair(servicer, _TIMEOUT)
        server = implementations.server()
        stub = implementations.stub(linked_pair.front, stub_pool)
        return server, stub, (servicer_pool, stub_pool, linked_pair)
Esempio n. 2
0
  def set_up_implementation(
      self,
      name,
      methods,
      inline_value_in_value_out_methods,
      inline_value_in_stream_out_methods,
      inline_stream_in_value_out_methods,
      inline_stream_in_stream_out_methods,
      event_value_in_value_out_methods,
      event_value_in_stream_out_methods,
      event_stream_in_value_out_methods,
      event_stream_in_stream_out_methods,
      multi_method):
    servicer_pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)
    stub_pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

    servicer = implementations.servicer(
        servicer_pool,
        inline_value_in_value_out_methods=inline_value_in_value_out_methods,
        inline_value_in_stream_out_methods=inline_value_in_stream_out_methods,
        inline_stream_in_value_out_methods=inline_stream_in_value_out_methods,
        inline_stream_in_stream_out_methods=inline_stream_in_stream_out_methods,
        event_value_in_value_out_methods=event_value_in_value_out_methods,
        event_value_in_stream_out_methods=event_value_in_stream_out_methods,
        event_stream_in_value_out_methods=event_stream_in_value_out_methods,
        event_stream_in_stream_out_methods=event_stream_in_stream_out_methods,
        multi_method=multi_method)

    linked_pair = base_util.linked_pair(servicer, _TIMEOUT)
    server = implementations.server()
    stub = implementations.stub(linked_pair.front, stub_pool)
    return server, stub, (servicer_pool, stub_pool, linked_pair)
Esempio n. 3
0
 def __enter__(self):
   with self._lock:
     self._pool = logging_pool.pool(_THREAD_POOL_SIZE)
     self._front = tickets_implementations.front(
         self._pool, self._pool, self._pool)
     self._rear_link.start()
     self._rear_link.join_fore_link(self._front)
     self._front.join_rear_link(self._rear_link)
     self._under_stub = face_implementations.stub(self._front, self._pool)
Esempio n. 4
0
  def set_up_implementation(
      self,
      name,
      methods,
      inline_value_in_value_out_methods,
      inline_value_in_stream_out_methods,
      inline_stream_in_value_out_methods,
      inline_stream_in_stream_out_methods,
      event_value_in_value_out_methods,
      event_value_in_stream_out_methods,
      event_stream_in_value_out_methods,
      event_stream_in_stream_out_methods,
      multi_method):
    pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

    servicer = face_implementations.servicer(
        pool,
        inline_value_in_value_out_methods=inline_value_in_value_out_methods,
        inline_value_in_stream_out_methods=inline_value_in_stream_out_methods,
        inline_stream_in_value_out_methods=inline_stream_in_value_out_methods,
        inline_stream_in_stream_out_methods=inline_stream_in_stream_out_methods,
        event_value_in_value_out_methods=event_value_in_value_out_methods,
        event_value_in_stream_out_methods=event_value_in_stream_out_methods,
        event_stream_in_value_out_methods=event_stream_in_value_out_methods,
        event_stream_in_stream_out_methods=event_stream_in_stream_out_methods,
        multi_method=multi_method)

    serialization = serial.serialization(methods)

    fore_link = fore.ForeLink(
        pool, serialization.request_deserializers,
        serialization.response_serializers, None, ())
    fore_link.start()
    port = fore_link.port()
    rear_link = rear.RearLink(
        'localhost', port, pool,
        serialization.request_serializers,
        serialization.response_deserializers, False, None, None, None)
    rear_link.start()
    front = tickets_implementations.front(pool, pool, pool)
    back = tickets_implementations.back(
        servicer, pool, pool, pool, _TIMEOUT, _MAXIMUM_TIMEOUT)
    fore_link.join_rear_link(back)
    back.join_fore_link(fore_link)
    rear_link.join_fore_link(front)
    front.join_rear_link(rear_link)

    server = face_implementations.server()
    stub = face_implementations.stub(front, pool)
    return server, stub, (rear_link, fore_link, front, back)
Esempio n. 5
0
    def set_up_implementation(self, name, methods,
                              inline_value_in_value_out_methods,
                              inline_value_in_stream_out_methods,
                              inline_stream_in_value_out_methods,
                              inline_stream_in_stream_out_methods,
                              event_value_in_value_out_methods,
                              event_value_in_stream_out_methods,
                              event_stream_in_value_out_methods,
                              event_stream_in_stream_out_methods,
                              multi_method):
        pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

        servicer = face_implementations.servicer(
            pool,
            inline_value_in_value_out_methods=inline_value_in_value_out_methods,
            inline_value_in_stream_out_methods=
            inline_value_in_stream_out_methods,
            inline_stream_in_value_out_methods=
            inline_stream_in_value_out_methods,
            inline_stream_in_stream_out_methods=
            inline_stream_in_stream_out_methods,
            event_value_in_value_out_methods=event_value_in_value_out_methods,
            event_value_in_stream_out_methods=event_value_in_stream_out_methods,
            event_stream_in_value_out_methods=event_stream_in_value_out_methods,
            event_stream_in_stream_out_methods=
            event_stream_in_stream_out_methods,
            multi_method=multi_method)

        serialization = serial.serialization(methods)

        fore_link = fore.ForeLink(pool, serialization.request_deserializers,
                                  serialization.response_serializers, None, ())
        fore_link.start()
        port = fore_link.port()
        rear_link = rear.RearLink('localhost', port, pool,
                                  serialization.request_serializers,
                                  serialization.response_deserializers, False,
                                  None, None, None)
        rear_link.start()
        front = tickets_implementations.front(pool, pool, pool)
        back = tickets_implementations.back(servicer, pool, pool, pool,
                                            _TIMEOUT, _MAXIMUM_TIMEOUT)
        fore_link.join_rear_link(back)
        back.join_fore_link(fore_link)
        rear_link.join_fore_link(front)
        front.join_rear_link(rear_link)

        server = face_implementations.server()
        stub = face_implementations.stub(front, pool)
        return server, stub, (rear_link, fore_link, front, back)
Esempio n. 6
0
def _behaviors(implementations, front, pool):
  behaviors = {}
  stub = face_implementations.stub(front, pool)
  for name, implementation in six.iteritems(implementations):
    if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY:
      behaviors[name] = stub.unary_unary_sync_async(name)
    elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM:
      behaviors[name] = lambda request, context, bound_name=name: (
          stub.inline_value_in_stream_out(bound_name, request, context))
    elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY:
      behaviors[name] = stub.stream_unary_sync_async(name)
    elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM:
      behaviors[name] = lambda request_iterator, context, bound_name=name: (
          stub.inline_stream_in_stream_out(
              bound_name, request_iterator, context))
  return behaviors
Esempio n. 7
0
def server_and_stub(default_timeout,
                    inline_value_in_value_out_methods=None,
                    inline_value_in_stream_out_methods=None,
                    inline_stream_in_value_out_methods=None,
                    inline_stream_in_stream_out_methods=None,
                    event_value_in_value_out_methods=None,
                    event_value_in_stream_out_methods=None,
                    event_stream_in_value_out_methods=None,
                    event_stream_in_stream_out_methods=None,
                    multi_method=None):
    """Creates a Server and Stub linked together for use."""
    front_work_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    front_transmission_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    front_utility_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    back_work_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    back_transmission_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    back_utility_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    stub_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    pools = (front_work_pool, front_transmission_pool, front_utility_pool,
             back_work_pool, back_transmission_pool, back_utility_pool,
             stub_pool)

    servicer = implementations.servicer(
        back_work_pool,
        inline_value_in_value_out_methods=inline_value_in_value_out_methods,
        inline_value_in_stream_out_methods=inline_value_in_stream_out_methods,
        inline_stream_in_value_out_methods=inline_stream_in_value_out_methods,
        inline_stream_in_stream_out_methods=inline_stream_in_stream_out_methods,
        event_value_in_value_out_methods=event_value_in_value_out_methods,
        event_value_in_stream_out_methods=event_value_in_stream_out_methods,
        event_stream_in_value_out_methods=event_stream_in_value_out_methods,
        event_stream_in_stream_out_methods=event_stream_in_stream_out_methods,
        multi_method=multi_method)

    front = _tickets_implementations.front(front_work_pool,
                                           front_transmission_pool,
                                           front_utility_pool)
    back = _tickets_implementations.back(servicer, back_work_pool,
                                         back_transmission_pool,
                                         back_utility_pool, default_timeout,
                                         _MAXIMUM_TIMEOUT)
    front.join_rear_link(back)
    back.join_fore_link(front)

    stub = implementations.stub(front, stub_pool)

    return _LinkedPair(implementations.server(), stub, front, back, pools)
Esempio n. 8
0
def server_and_stub(
    default_timeout,
    inline_value_in_value_out_methods=None,
    inline_value_in_stream_out_methods=None,
    inline_stream_in_value_out_methods=None,
    inline_stream_in_stream_out_methods=None,
    event_value_in_value_out_methods=None,
    event_value_in_stream_out_methods=None,
    event_stream_in_value_out_methods=None,
    event_stream_in_stream_out_methods=None,
    multi_method=None):
  """Creates a Server and Stub linked together for use."""
  front_work_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  front_transmission_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  front_utility_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  back_work_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  back_transmission_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  back_utility_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  stub_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  pools = (
      front_work_pool, front_transmission_pool, front_utility_pool,
      back_work_pool, back_transmission_pool, back_utility_pool,
      stub_pool)

  servicer = implementations.servicer(
      back_work_pool,
      inline_value_in_value_out_methods=inline_value_in_value_out_methods,
      inline_value_in_stream_out_methods=inline_value_in_stream_out_methods,
      inline_stream_in_value_out_methods=inline_stream_in_value_out_methods,
      inline_stream_in_stream_out_methods=inline_stream_in_stream_out_methods,
      event_value_in_value_out_methods=event_value_in_value_out_methods,
      event_value_in_stream_out_methods=event_value_in_stream_out_methods,
      event_stream_in_value_out_methods=event_stream_in_value_out_methods,
      event_stream_in_stream_out_methods=event_stream_in_stream_out_methods,
      multi_method=multi_method)

  front = _tickets_implementations.front(
      front_work_pool, front_transmission_pool, front_utility_pool)
  back = _tickets_implementations.back(
      servicer, back_work_pool, back_transmission_pool, back_utility_pool,
      default_timeout, _MAXIMUM_TIMEOUT)
  front.join_rear_link(back)
  back.join_fore_link(front)

  stub = implementations.stub(front, stub_pool)

  return _LinkedPair(implementations.server(), stub, front, back, pools)