Add a port method to assembly-level servers.

pull/732/head
Nathaniel Manista 10 years ago
parent 275e975c53
commit de16e4c755
  1. 8
      src/python/src/grpc/framework/assembly/implementations.py
  2. 23
      src/python/src/grpc/framework/assembly/interfaces.py

@ -195,7 +195,7 @@ def _servicer(implementations, pool):
event_stream_in_stream_out_methods=event_stream_in_stream_out_methods) event_stream_in_stream_out_methods=event_stream_in_stream_out_methods)
class _ServiceAssembly(activated.Activated): class _ServiceAssembly(interfaces.Server):
def __init__(self, implementations, fore_link): def __init__(self, implementations, fore_link):
self._implementations = implementations self._implementations = implementations
@ -237,6 +237,10 @@ class _ServiceAssembly(activated.Activated):
def stop(self): def stop(self):
self._stop() self._stop()
def port(self):
with self._lock:
return self._fore_link.port()
def assemble_face_stub(activated_rear_link): def assemble_face_stub(activated_rear_link):
"""Assembles a face_interfaces.Stub. """Assembles a face_interfaces.Stub.
@ -300,6 +304,6 @@ def assemble_service(implementations, activated_fore_link):
when passed to this method. when passed to this method.
Returns: Returns:
An activated.Activated value encapsulating RPC service. An interfaces.Server encapsulating RPC service.
""" """
return _ServiceAssembly(implementations, activated_fore_link) return _ServiceAssembly(implementations, activated_fore_link)

@ -37,6 +37,7 @@ import abc
# module. # module.
from grpc.framework.common import cardinality # pylint: disable=unused-import from grpc.framework.common import cardinality # pylint: disable=unused-import
from grpc.framework.common import style # pylint: disable=unused-import from grpc.framework.common import style # pylint: disable=unused-import
from grpc.framework.foundation import activated
from grpc.framework.foundation import stream # pylint: disable=unused-import from grpc.framework.foundation import stream # pylint: disable=unused-import
@ -89,3 +90,25 @@ class MethodImplementation(object):
style.Service.EVENT. style.Service.EVENT.
""" """
__metaclass__ = abc.ABCMeta __metaclass__ = abc.ABCMeta
class Server(activated.Activated):
"""The server interface.
Aside from being able to be activated and deactivated, objects of this type
are able to report the port on which they are servicing RPCs.
"""
__metaclass__ = abc.ABCMeta
# TODO(issue 726): This is an abstraction violation; not every Server is
# necessarily serving over a network at all.
@abc.abstractmethod
def port(self):
"""Identifies the port on which this Server is servicing RPCs.
This method may only be called while the server is active.
Returns:
The number of the port on which this Server is servicing RPCs.
"""
raise NotImplementedError()

Loading…
Cancel
Save