Exemplo n.º 1
0
def linked_pair(servicer, default_timeout):
    """Creates a Server and Stub linked together for use."""
    link_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
    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)
    pools = (link_pool, front_work_pool, front_transmission_pool,
             front_utility_pool, back_work_pool, back_transmission_pool,
             back_utility_pool)

    link = in_memory.Link(link_pool)
    front = implementations.front_link(front_work_pool,
                                       front_transmission_pool,
                                       front_utility_pool)
    back = implementations.back_link(servicer, back_work_pool,
                                     back_transmission_pool, back_utility_pool,
                                     default_timeout, _MAXIMUM_TIMEOUT)
    front.join_rear_link(link)
    link.join_fore_link(front)
    back.join_fore_link(link)
    link.join_rear_link(back)

    return _LinkedPair(front, back, pools)
Exemplo n.º 2
0
 def __enter__(self):
     with self._lock:
         if self._pool is None:
             self._pool = logging_pool.pool(_THREAD_POOL_SIZE)
             self._front = _base_implementations.front_link(self._pool, self._pool, self._pool)
             self._rear_link = _rear.RearLink(
                 self._host,
                 self._port,
                 self._pool,
                 self._breakdown.request_serializers,
                 self._breakdown.response_deserializers,
                 self._secure,
                 self._root_certificates,
                 self._private_key,
                 self._certificate_chain,
                 metadata_transformer=self._metadata_transformer,
                 server_host_override=self._server_host_override,
             )
             self._front.join_rear_link(self._rear_link)
             self._rear_link.join_fore_link(self._front)
             self._rear_link.start()
             self._understub = _face_implementations.dynamic_stub(
                 self._breakdown.face_cardinalities, self._front, self._pool, ""
             )
         else:
             raise ValueError("Tried to __enter__ already-__enter__ed Stub!")
     return self
Exemplo n.º 3
0
def linked_pair(servicer, default_timeout):
  """Creates a Server and Stub linked together for use."""
  link_pool = logging_pool.pool(_POOL_SIZE_LIMIT)
  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)
  pools = (
      link_pool,
      front_work_pool, front_transmission_pool, front_utility_pool,
      back_work_pool, back_transmission_pool, back_utility_pool)

  link = in_memory.Link(link_pool)
  front = implementations.front_link(
      front_work_pool, front_transmission_pool, front_utility_pool)
  back = implementations.back_link(
      servicer, back_work_pool, back_transmission_pool, back_utility_pool,
      default_timeout, _MAXIMUM_TIMEOUT)
  front.join_rear_link(link)
  link.join_fore_link(front)
  back.join_fore_link(link)
  link.join_rear_link(back)

  return _LinkedPair(front, back, pools)
Exemplo n.º 4
0
 def __enter__(self):
     with self._lock:
         if self._pool is None:
             self._pool = logging_pool.pool(_THREAD_POOL_SIZE)
             self._front = _base_implementations.front_link(
                 self._pool, self._pool, self._pool)
             self._rear_link = _rear.RearLink(
                 self._host,
                 self._port,
                 self._pool,
                 self._breakdown.request_serializers,
                 self._breakdown.response_deserializers,
                 self._secure,
                 self._root_certificates,
                 self._private_key,
                 self._certificate_chain,
                 metadata_transformer=self._metadata_transformer,
                 server_host_override=self._server_host_override)
             self._front.join_rear_link(self._rear_link)
             self._rear_link.join_fore_link(self._front)
             self._rear_link.start()
             self._understub = _face_implementations.dynamic_stub(
                 self._breakdown.face_cardinalities, self._front,
                 self._pool, '')
         else:
             raise ValueError(
                 'Tried to __enter__ already-__enter__ed Stub!')
     return self
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo 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 = _base_implementations.front_link(
      front_work_pool, front_transmission_pool, front_utility_pool)
  back = _base_implementations.back_link(
      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)
Exemplo n.º 8
0
 def setUp(self):
   self.memory_transmission_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.front_work_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.front_transmission_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.front_utility_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.back_work_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.back_transmission_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.back_utility_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.test_pool = logging_pool.pool(POOL_MAX_WORKERS)
   self.test_servicer = interfaces_test_case.TestServicer(self.test_pool)
   self.front = implementations.front_link(
       self.front_work_pool, self.front_transmission_pool,
       self.front_utility_pool)
   self.back = implementations.back_link(
       self.test_servicer, self.back_work_pool, self.back_transmission_pool,
       self.back_utility_pool, DEFAULT_TIMEOUT, MAXIMUM_TIMEOUT)
   self.front.join_rear_link(self.back)
   self.back.join_fore_link(self.front)