コード例 #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)
コード例 #2
0
    def set_up_implementation(self, name, methods, method_implementations,
                              multi_method_implementation):
        pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

        servicer = face_implementations.servicer(pool, method_implementations,
                                                 multi_method_implementation)

        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 = base_implementations.front_link(pool, pool, pool)
        back = base_implementations.back_link(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)

        stub = face_implementations.generic_stub(front, pool)
        return stub, (rear_link, fore_link, front, back)
コード例 #3
0
ファイル: _face_test_case.py プロジェクト: larsonmpdx/grpc
  def set_up_implementation(
      self, name, methods, method_implementations,
      multi_method_implementation):
    pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

    servicer = face_implementations.servicer(
        pool, method_implementations, multi_method_implementation)

    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 = base_implementations.front_link(pool, pool, pool)
    back = base_implementations.back_link(
        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)

    stub = face_implementations.generic_stub(front, pool)
    return stub, (rear_link, fore_link, front, back)
コード例 #4
0
ファイル: _test_case.py プロジェクト: mindis/grpc
  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)
コード例 #5
0
ファイル: implementations.py プロジェクト: zhangf911/grpc
def _servicer(implementations, pool):
    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 = {}

    for name, implementation in implementations.iteritems():
        if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY:
            if implementation.style is style.Service.INLINE:
                inline_value_in_value_out_methods[name] = (
                    face_utilities.inline_unary_unary_method(
                        implementation.unary_unary_inline))
            elif implementation.style is style.Service.EVENT:
                event_value_in_value_out_methods[name] = (
                    face_utilities.event_unary_unary_method(
                        implementation.unary_unary_event))
        elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM:
            if implementation.style is style.Service.INLINE:
                inline_value_in_stream_out_methods[name] = (
                    face_utilities.inline_unary_stream_method(
                        implementation.unary_stream_inline))
            elif implementation.style is style.Service.EVENT:
                event_value_in_stream_out_methods[name] = (
                    face_utilities.event_unary_stream_method(
                        implementation.unary_stream_event))
        if implementation.cardinality is cardinality.Cardinality.STREAM_UNARY:
            if implementation.style is style.Service.INLINE:
                inline_stream_in_value_out_methods[name] = (
                    face_utilities.inline_stream_unary_method(
                        implementation.stream_unary_inline))
            elif implementation.style is style.Service.EVENT:
                event_stream_in_value_out_methods[name] = (
                    face_utilities.event_stream_unary_method(
                        implementation.stream_unary_event))
        elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM:
            if implementation.style is style.Service.INLINE:
                inline_stream_in_stream_out_methods[name] = (
                    face_utilities.inline_stream_stream_method(
                        implementation.stream_stream_inline))
            elif implementation.style is style.Service.EVENT:
                event_stream_in_stream_out_methods[name] = (
                    face_utilities.event_stream_stream_method(
                        implementation.stream_stream_event))

    return 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)
コード例 #6
0
  def set_up_implementation(
      self, name, methods, method_implementations,
      multi_method_implementation):
    servicer_pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)
    stub_pool = logging_pool.pool(_MAXIMUM_POOL_SIZE)

    servicer = implementations.servicer(
        servicer_pool, method_implementations, multi_method_implementation)

    linked_pair = base_util.linked_pair(servicer, _TIMEOUT)
    stub = implementations.generic_stub(linked_pair.front, stub_pool)
    return stub, (servicer_pool, stub_pool, linked_pair)
コード例 #7
0
ファイル: implementations.py プロジェクト: mindis/grpc
def _servicer(implementations, pool):
  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 = {}

  for name, implementation in six.iteritems(implementations):
    if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY:
      if implementation.style is style.Service.INLINE:
        inline_value_in_value_out_methods[name] = (
            face_utilities.inline_unary_unary_method(implementation.unary_unary_inline))
      elif implementation.style is style.Service.EVENT:
        event_value_in_value_out_methods[name] = (
            face_utilities.event_unary_unary_method(implementation.unary_unary_event))
    elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM:
      if implementation.style is style.Service.INLINE:
        inline_value_in_stream_out_methods[name] = (
            face_utilities.inline_unary_stream_method(implementation.unary_stream_inline))
      elif implementation.style is style.Service.EVENT:
        event_value_in_stream_out_methods[name] = (
            face_utilities.event_unary_stream_method(implementation.unary_stream_event))
    if implementation.cardinality is cardinality.Cardinality.STREAM_UNARY:
      if implementation.style is style.Service.INLINE:
        inline_stream_in_value_out_methods[name] = (
            face_utilities.inline_stream_unary_method(implementation.stream_unary_inline))
      elif implementation.style is style.Service.EVENT:
        event_stream_in_value_out_methods[name] = (
            face_utilities.event_stream_unary_method(implementation.stream_unary_event))
    elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM:
      if implementation.style is style.Service.INLINE:
        inline_stream_in_stream_out_methods[name] = (
            face_utilities.inline_stream_stream_method(implementation.stream_stream_inline))
      elif implementation.style is style.Service.EVENT:
        event_stream_in_stream_out_methods[name] = (
            face_utilities.event_stream_stream_method(implementation.stream_stream_event))

  return 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)
コード例 #8
0
ファイル: _face_test_case.py プロジェクト: mindis/grpc
  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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
0
ファイル: demonstration.py プロジェクト: mindis/grpc
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)
コード例 #12
0
ファイル: implementations.py プロジェクト: AddictXQ/grpc
 def _start(self):
   with self._lock:
     if self._pool is None:
       self._pool = logging_pool.pool(_THREAD_POOL_SIZE)
       servicer = _face_implementations.servicer(
           self._pool, self._breakdown.implementations, None)
       self._back = _base_implementations.back_link(
           servicer, self._pool, self._pool, self._pool, _ONE_DAY_IN_SECONDS,
           _ONE_DAY_IN_SECONDS)
       self._fore_link = _fore.ForeLink(
           self._pool, self._breakdown.request_deserializers,
           self._breakdown.response_serializers, None, self._key_chain_pairs,
           port=self._port)
       self._back.join_fore_link(self._fore_link)
       self._fore_link.join_rear_link(self._back)
       self._fore_link.start()
     else:
       raise ValueError('Server currently running!')
コード例 #13
0
ファイル: implementations.py プロジェクト: wfarr/grpc
 def _start(self):
     with self._lock:
         if self._pool is None:
             self._pool = logging_pool.pool(_THREAD_POOL_SIZE)
             servicer = _face_implementations.servicer(
                 self._pool, self._breakdown.implementations, None)
             self._back = _base_implementations.back_link(
                 servicer, self._pool, self._pool, self._pool,
                 _ONE_DAY_IN_SECONDS, _ONE_DAY_IN_SECONDS)
             self._fore_link = _fore.ForeLink(
                 self._pool,
                 self._breakdown.request_deserializers,
                 self._breakdown.response_serializers,
                 None,
                 self._key_chain_pairs,
                 port=self._port)
             self._back.join_fore_link(self._fore_link)
             self._fore_link.join_rear_link(self._back)
             self._fore_link.start()
         else:
             raise ValueError('Server currently running!')