diff options
-rw-r--r-- | src/python/src/grpc/framework/assembly/implementations.py | 8 | ||||
-rw-r--r-- | src/python/src/grpc/framework/assembly/interfaces.py | 23 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/python/src/grpc/framework/assembly/implementations.py b/src/python/src/grpc/framework/assembly/implementations.py index 461aa9c855..b9d314844c 100644 --- a/src/python/src/grpc/framework/assembly/implementations.py +++ b/src/python/src/grpc/framework/assembly/implementations.py @@ -195,7 +195,7 @@ def _servicer(implementations, pool): 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): self._implementations = implementations @@ -237,6 +237,10 @@ class _ServiceAssembly(activated.Activated): def stop(self): self._stop() + def port(self): + with self._lock: + return self._fore_link.port() + def assemble_face_stub(activated_rear_link): """Assembles a face_interfaces.Stub. @@ -300,6 +304,6 @@ def assemble_service(implementations, activated_fore_link): when passed to this method. Returns: - An activated.Activated value encapsulating RPC service. + An interfaces.Server encapsulating RPC service. """ return _ServiceAssembly(implementations, activated_fore_link) diff --git a/src/python/src/grpc/framework/assembly/interfaces.py b/src/python/src/grpc/framework/assembly/interfaces.py index e5d750b2bc..d1a6aad29e 100644 --- a/src/python/src/grpc/framework/assembly/interfaces.py +++ b/src/python/src/grpc/framework/assembly/interfaces.py @@ -37,6 +37,7 @@ import abc # module. from grpc.framework.common import cardinality # 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 @@ -89,3 +90,25 @@ class MethodImplementation(object): style.Service.EVENT. """ __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() |