def instantiate(self, serializations, servicer):
    serialization_behaviors = _serialization_behaviors_from_serializations(
        serializations)
    invocation_end_link = implementations.invocation_end_link()
    service_end_link = implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    service_grpc_link = service.service_link(
        serialization_behaviors.request_deserializers,
        serialization_behaviors.response_serializers)
    port = service_grpc_link.add_port('[::]:0', None)
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_grpc_link = invocation.invocation_link(
        channel, b'localhost', None,
        serialization_behaviors.request_serializers,
        serialization_behaviors.response_deserializers)

    invocation_end_link.join_link(invocation_grpc_link)
    invocation_grpc_link.join_link(invocation_end_link)
    service_end_link.join_link(service_grpc_link)
    service_grpc_link.join_link(service_end_link)
    invocation_grpc_link.start()
    service_grpc_link.start()
    return invocation_end_link, service_end_link, (
        invocation_grpc_link, service_grpc_link)
    def instantiate(self, methods, method_implementations,
                    multi_method_implementation):
        pool = logging_pool.pool(test_constants.POOL_SIZE)
        servicer = crust_implementations.servicer(method_implementations,
                                                  multi_method_implementation,
                                                  pool)

        service_end_link = core_implementations.service_end_link(
            servicer, test_constants.DEFAULT_TIMEOUT,
            test_constants.MAXIMUM_TIMEOUT)
        invocation_end_link = core_implementations.invocation_end_link()
        invocation_end_link.join_link(service_end_link)
        service_end_link.join_link(invocation_end_link)
        service_end_link.start()
        invocation_end_link.start()

        generic_stub = crust_implementations.generic_stub(
            invocation_end_link, pool)
        # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
        group = next(iter(methods))[0]
        # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
        # _digest.TestServiceDigest.
        cardinalities = {
            method: method_object.cardinality()
            for (group, method), method_object in six.iteritems(methods)
        }
        dynamic_stub = crust_implementations.dynamic_stub(
            invocation_end_link, group, cardinalities, pool)

        return generic_stub, {
            group: dynamic_stub
        }, (invocation_end_link, service_end_link, pool)
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    pool = logging_pool.pool(test_constants.POOL_SIZE)
    servicer = crust_implementations.servicer(
        method_implementations, multi_method_implementation, pool)

    service_end_link = core_implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    invocation_end_link = core_implementations.invocation_end_link()
    invocation_end_link.join_link(service_end_link)
    service_end_link.join_link(invocation_end_link)
    service_end_link.start()
    invocation_end_link.start()

    generic_stub = crust_implementations.generic_stub(invocation_end_link, pool)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    group = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in methods.iteritems()}
    dynamic_stub = crust_implementations.dynamic_stub(
        invocation_end_link, group, cardinalities, pool)

    return generic_stub, {group: dynamic_stub}, (
        invocation_end_link, service_end_link, pool)
  def instantiate(self, serializations, servicer):
    serialization_behaviors = _serialization_behaviors_from_serializations(
        serializations)
    invocation_end_link = implementations.invocation_end_link()
    service_end_link = implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    service_grpc_link = service.service_link(
        serialization_behaviors.request_deserializers,
        serialization_behaviors.response_serializers)
    port = service_grpc_link.add_port('[::]:0', None)
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_grpc_link = invocation.invocation_link(
        channel, b'localhost', None,
        serialization_behaviors.request_serializers,
        serialization_behaviors.response_deserializers)

    invocation_end_link.join_link(invocation_grpc_link)
    invocation_grpc_link.join_link(invocation_end_link)
    service_end_link.join_link(service_grpc_link)
    service_grpc_link.join_link(service_end_link)
    invocation_grpc_link.start()
    service_grpc_link.start()
    return invocation_end_link, service_end_link, (
        invocation_grpc_link, service_grpc_link)
Example #5
0
def server(implementations, multi_implementation, request_deserializers,
           response_serializers, thread_pool, thread_pool_size,
           default_timeout, maximum_timeout):
    if thread_pool is None:
        service_thread_pool = logging_pool.pool(
            _DEFAULT_POOL_SIZE
            if thread_pool_size is None else thread_pool_size)
        assembly_thread_pool = service_thread_pool
    else:
        service_thread_pool = thread_pool
        assembly_thread_pool = None

    servicer = _GRPCServicer(
        _crust_implementations.servicer(implementations, multi_implementation,
                                        service_thread_pool))

    grpc_link = service.service_link(request_deserializers,
                                     response_serializers)

    end_link = _core_implementations.service_end_link(
        servicer,
        _DEFAULT_TIMEOUT if default_timeout is None else default_timeout,
        _MAXIMUM_TIMEOUT if maximum_timeout is None else maximum_timeout)

    return Server(grpc_link, end_link, assembly_thread_pool)
 def instantiate(self, serializations, servicer):
     invocation = implementations.invocation_end_link()
     service = implementations.service_end_link(
         servicer, test_constants.DEFAULT_TIMEOUT,
         test_constants.MAXIMUM_TIMEOUT)
     invocation.join_link(service)
     service.join_link(invocation)
     return invocation, service, None
Example #7
0
 def instantiate(self, serializations, servicer):
     invocation = implementations.invocation_end_link()
     service = implementations.service_end_link(
         servicer, test_constants.DEFAULT_TIMEOUT, test_constants.MAXIMUM_TIMEOUT
     )
     invocation.join_link(service)
     service.join_link(invocation)
     return invocation, service, None
    def instantiate(self, methods, method_implementations,
                    multi_method_implementation):
        pool = logging_pool.pool(test_constants.POOL_SIZE)
        servicer = crust_implementations.servicer(method_implementations,
                                                  multi_method_implementation,
                                                  pool)
        serialization_behaviors = _serialization_behaviors_from_test_methods(
            methods)
        invocation_end_link = core_implementations.invocation_end_link()
        service_end_link = core_implementations.service_end_link(
            servicer, test_constants.DEFAULT_TIMEOUT,
            test_constants.MAXIMUM_TIMEOUT)
        service_grpc_link = service.service_link(
            serialization_behaviors.request_deserializers,
            serialization_behaviors.response_serializers)
        port = service_grpc_link.add_port('[::]:0', None)
        channel = _intermediary_low.Channel('localhost:%d' % port, None)
        invocation_grpc_link = invocation.invocation_link(
            channel, b'localhost', None,
            serialization_behaviors.request_serializers,
            serialization_behaviors.response_deserializers)

        invocation_end_link.join_link(invocation_grpc_link)
        invocation_grpc_link.join_link(invocation_end_link)
        service_grpc_link.join_link(service_end_link)
        service_end_link.join_link(service_grpc_link)
        service_end_link.start()
        invocation_end_link.start()
        invocation_grpc_link.start()
        service_grpc_link.start()

        generic_stub = crust_implementations.generic_stub(
            invocation_end_link, pool)
        # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
        group = next(iter(methods))[0]
        # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
        # _digest.TestServiceDigest.
        cardinalities = {
            method: method_object.cardinality()
            for (group, method), method_object in six.iteritems(methods)
        }
        dynamic_stub = crust_implementations.dynamic_stub(
            invocation_end_link, group, cardinalities, pool)

        return generic_stub, {
            group: dynamic_stub
        }, (invocation_end_link, invocation_grpc_link, service_grpc_link,
            service_end_link, pool)
  def instantiate(
      self, methods, method_implementations, multi_method_implementation):
    pool = logging_pool.pool(test_constants.POOL_SIZE)
    servicer = crust_implementations.servicer(
        method_implementations, multi_method_implementation, pool)
    serialization_behaviors = _serialization_behaviors_from_test_methods(
        methods)
    invocation_end_link = core_implementations.invocation_end_link()
    service_end_link = core_implementations.service_end_link(
        servicer, test_constants.DEFAULT_TIMEOUT,
        test_constants.MAXIMUM_TIMEOUT)
    service_grpc_link = service.service_link(
        serialization_behaviors.request_deserializers,
        serialization_behaviors.response_serializers)
    port = service_grpc_link.add_port('[::]:0', None)
    channel = _intermediary_low.Channel('localhost:%d' % port, None)
    invocation_grpc_link = invocation.invocation_link(
        channel, b'localhost',
        serialization_behaviors.request_serializers,
        serialization_behaviors.response_deserializers)

    invocation_end_link.join_link(invocation_grpc_link)
    invocation_grpc_link.join_link(invocation_end_link)
    service_grpc_link.join_link(service_end_link)
    service_end_link.join_link(service_grpc_link)
    service_end_link.start()
    invocation_end_link.start()
    invocation_grpc_link.start()
    service_grpc_link.start()

    generic_stub = crust_implementations.generic_stub(invocation_end_link, pool)
    # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest.
    group = next(iter(methods))[0]
    # TODO(nathaniel): Add a "cardinalities_by_group" attribute to
    # _digest.TestServiceDigest.
    cardinalities = {
        method: method_object.cardinality()
        for (group, method), method_object in methods.iteritems()}
    dynamic_stub = crust_implementations.dynamic_stub(
        invocation_end_link, group, cardinalities, pool)

    return generic_stub, {group: dynamic_stub}, (
        invocation_end_link, invocation_grpc_link, service_grpc_link,
        service_end_link, pool)
Example #10
0
  def _start(self):
    with self._lock:
      if self._end_link is not None:
        raise ValueError('Cannot start already-started server!')

      if self._customer_pool is None:
        self._pool = logging_pool.pool(self._pool_size)
        assembly_pool = self._pool
      else:
        assembly_pool = self._customer_pool

      servicer = _GRPCServicer(
          _crust_implementations.servicer(
              self._implementations, self._multi_implementation, assembly_pool))

      self._end_link = _core_implementations.service_end_link(
          servicer, self._default_timeout, self._maximum_timeout)

      self._grpc_link.join_link(self._end_link)
      self._end_link.join_link(self._grpc_link)
      self._grpc_link.start()
      self._end_link.start()
Example #11
0
  def _start(self):
    with self._lock:
      if self._end_link is not None:
        raise ValueError('Cannot start already-started server!')

      if self._customer_pool is None:
        self._pool = logging_pool.pool(self._pool_size)
        assembly_pool = self._pool
      else:
        assembly_pool = self._customer_pool

      servicer = _GRPCServicer(
          _crust_implementations.servicer(
              self._implementations, self._multi_implementation, assembly_pool))

      self._end_link = _core_implementations.service_end_link(
          servicer, self._default_timeout, self._maximum_timeout)

      self._grpc_link.join_link(self._end_link)
      self._end_link.join_link(self._grpc_link)
      self._grpc_link.start()
      self._end_link.start()
Example #12
0
def server(
    implementations, multi_implementation, request_deserializers,
    response_serializers, thread_pool, thread_pool_size, default_timeout,
    maximum_timeout):
  if thread_pool is None:
    service_thread_pool = logging_pool.pool(
        _DEFAULT_POOL_SIZE if thread_pool_size is None else thread_pool_size)
    assembly_thread_pool = service_thread_pool
  else:
    service_thread_pool = thread_pool
    assembly_thread_pool = None

  servicer = _crust_implementations.servicer(
      implementations, multi_implementation, service_thread_pool)

  grpc_link = service.service_link(request_deserializers, response_serializers)

  end_link = _core_implementations.service_end_link(
      servicer,
      _DEFAULT_TIMEOUT if default_timeout is None else default_timeout,
      _MAXIMUM_TIMEOUT if maximum_timeout is None else maximum_timeout)

  return Server(grpc_link, end_link, assembly_thread_pool)