From 4e6fd0a3aee0cedf22579ad02be82eac2798d25b Mon Sep 17 00:00:00 2001 From: Nathaniel Manista <nathaniel@google.com> Date: Wed, 18 Mar 2015 00:19:07 +0000 Subject: [PATCH] Merge the base and base.packets packages They were two halves of the same whole. --- .../src/grpc/_adapter/_face_test_case.py | 6 +- src/python/src/grpc/_adapter/_links_test.py | 60 ++++---- .../grpc/_adapter/_lonely_rear_link_test.py | 11 +- src/python/src/grpc/_adapter/_test_links.py | 2 +- src/python/src/grpc/_adapter/fore.py | 62 +++++---- src/python/src/grpc/_adapter/rear.py | 43 +++--- .../src/grpc/early_adopter/implementations.py | 6 +- .../base/{packets => }/_cancellation.py | 9 +- .../base/{packets => }/_constants.py | 0 .../framework/base/{packets => }/_context.py | 16 +-- .../framework/base/{packets => }/_emission.py | 15 +- .../framework/base/{packets => }/_ends.py | 74 +++++----- .../base/{packets => }/_expiration.py | 8 +- .../base/{packets => }/_ingestion.py | 5 +- .../base/{packets => }/_interfaces.py | 13 +- .../base/{packets => }/_reception.py | 71 +++++----- .../base/{packets => }/_termination.py | 4 +- .../base/{packets => }/_transmission.py | 51 ++++--- .../base/{packets => }/implementations.py | 44 +++--- .../{packets => }/implementations_test.py | 8 +- .../framework/base/{packets => }/in_memory.py | 4 +- .../src/grpc/framework/base/interfaces.py | 131 ++++++++++++++++++ .../grpc/framework/base/{packets => }/null.py | 2 +- .../grpc/framework/base/packets/__init__.py | 30 ---- .../grpc/framework/base/packets/interfaces.py | 84 ----------- .../grpc/framework/base/packets/packets.py | 118 ---------------- .../src/grpc/framework/face/demonstration.py | 6 +- .../grpc/framework/face/testing/base_util.py | 10 +- src/python/src/setup.py | 1 - tools/dockerfile/grpc_python/Dockerfile | 2 +- tools/run_tests/python_tests.json | 2 +- 31 files changed, 394 insertions(+), 504 deletions(-) rename src/python/src/grpc/framework/base/{packets => }/_cancellation.py (89%) rename src/python/src/grpc/framework/base/{packets => }/_constants.py (100%) rename src/python/src/grpc/framework/base/{packets => }/_context.py (86%) rename src/python/src/grpc/framework/base/{packets => }/_emission.py (89%) rename src/python/src/grpc/framework/base/{packets => }/_ends.py (86%) rename src/python/src/grpc/framework/base/{packets => }/_expiration.py (95%) rename src/python/src/grpc/framework/base/{packets => }/_ingestion.py (99%) rename src/python/src/grpc/framework/base/{packets => }/_interfaces.py (93%) rename src/python/src/grpc/framework/base/{packets => }/_reception.py (85%) rename src/python/src/grpc/framework/base/{packets => }/_termination.py (98%) rename src/python/src/grpc/framework/base/{packets => }/_transmission.py (91%) rename src/python/src/grpc/framework/base/{packets => }/implementations.py (77%) rename src/python/src/grpc/framework/base/{packets => }/implementations_test.py (94%) rename src/python/src/grpc/framework/base/{packets => }/in_memory.py (97%) rename src/python/src/grpc/framework/base/{packets => }/null.py (97%) delete mode 100644 src/python/src/grpc/framework/base/packets/__init__.py delete mode 100644 src/python/src/grpc/framework/base/packets/interfaces.py delete mode 100644 src/python/src/grpc/framework/base/packets/packets.py diff --git a/src/python/src/grpc/_adapter/_face_test_case.py b/src/python/src/grpc/_adapter/_face_test_case.py index 2542eb6da4..923e889844 100644 --- a/src/python/src/grpc/_adapter/_face_test_case.py +++ b/src/python/src/grpc/_adapter/_face_test_case.py @@ -34,7 +34,7 @@ import unittest from grpc._adapter import fore from grpc._adapter import rear from grpc.framework.base import util -from grpc.framework.base.packets import implementations as tickets_implementations +from grpc.framework.base import implementations as base_implementations from grpc.framework.face import implementations as face_implementations from grpc.framework.face.testing import coverage from grpc.framework.face.testing import serial @@ -69,8 +69,8 @@ class FaceTestCase(test_case.FaceTestCase, coverage.BlockingCoverage): serialization.request_serializers, serialization.response_deserializers, False, None, None, None) rear_link.start() - front = tickets_implementations.front(pool, pool, pool) - back = tickets_implementations.back( + 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) diff --git a/src/python/src/grpc/_adapter/_links_test.py b/src/python/src/grpc/_adapter/_links_test.py index 49fd1f7a1c..dc8ad15487 100644 --- a/src/python/src/grpc/_adapter/_links_test.py +++ b/src/python/src/grpc/_adapter/_links_test.py @@ -37,7 +37,6 @@ from grpc._adapter import _test_links from grpc._adapter import fore from grpc._adapter import rear from grpc.framework.base import interfaces -from grpc.framework.base.packets import packets as tickets from grpc.framework.foundation import logging_pool _IDENTITY = lambda x: x @@ -60,11 +59,11 @@ class RoundTripTest(unittest.TestCase): test_fore_link = _test_links.ForeLink(None, None) def rear_action(front_to_back_ticket, fore_link): if front_to_back_ticket.kind in ( - tickets.FrontToBackPacket.Kind.COMPLETION, - tickets.FrontToBackPacket.Kind.ENTIRE): - back_to_front_ticket = tickets.BackToFrontPacket( + interfaces.FrontToBackPacket.Kind.COMPLETION, + interfaces.FrontToBackPacket.Kind.ENTIRE): + back_to_front_ticket = interfaces.BackToFrontPacket( front_to_back_ticket.operation_id, 0, - tickets.BackToFrontPacket.Kind.COMPLETION, None) + interfaces.BackToFrontPacket.Kind.COMPLETION, None) fore_link.accept_back_to_front_ticket(back_to_front_ticket) test_rear_link = _test_links.RearLink(rear_action, None) @@ -82,8 +81,8 @@ class RoundTripTest(unittest.TestCase): test_fore_link.join_rear_link(rear_link) rear_link.start() - front_to_back_ticket = tickets.FrontToBackPacket( - test_operation_id, 0, tickets.FrontToBackPacket.Kind.ENTIRE, + front_to_back_ticket = interfaces.FrontToBackPacket( + test_operation_id, 0, interfaces.FrontToBackPacket.Kind.ENTIRE, test_method, interfaces.ServicedSubscription.Kind.FULL, None, None, _TIMEOUT) rear_link.accept_front_to_back_ticket(front_to_back_ticket) @@ -91,7 +90,7 @@ class RoundTripTest(unittest.TestCase): with test_fore_link.condition: while (not test_fore_link.tickets or test_fore_link.tickets[-1].kind is - tickets.BackToFrontPacket.Kind.CONTINUATION): + interfaces.BackToFrontPacket.Kind.CONTINUATION): test_fore_link.condition.wait() rear_link.stop() @@ -100,7 +99,7 @@ class RoundTripTest(unittest.TestCase): with test_fore_link.condition: self.assertIs( test_fore_link.tickets[-1].kind, - tickets.BackToFrontPacket.Kind.COMPLETION) + interfaces.BackToFrontPacket.Kind.COMPLETION) def testEntireRoundTrip(self): test_operation_id = object() @@ -115,14 +114,14 @@ class RoundTripTest(unittest.TestCase): else: payload = test_back_to_front_datum terminal = front_to_back_ticket.kind in ( - tickets.FrontToBackPacket.Kind.COMPLETION, - tickets.FrontToBackPacket.Kind.ENTIRE) + interfaces.FrontToBackPacket.Kind.COMPLETION, + interfaces.FrontToBackPacket.Kind.ENTIRE) if payload is not None or terminal: if terminal: - kind = tickets.BackToFrontPacket.Kind.COMPLETION + kind = interfaces.BackToFrontPacket.Kind.COMPLETION else: - kind = tickets.BackToFrontPacket.Kind.CONTINUATION - back_to_front_ticket = tickets.BackToFrontPacket( + kind = interfaces.BackToFrontPacket.Kind.CONTINUATION + back_to_front_ticket = interfaces.BackToFrontPacket( front_to_back_ticket.operation_id, rear_sequence_number[0], kind, payload) rear_sequence_number[0] += 1 @@ -144,8 +143,8 @@ class RoundTripTest(unittest.TestCase): test_fore_link.join_rear_link(rear_link) rear_link.start() - front_to_back_ticket = tickets.FrontToBackPacket( - test_operation_id, 0, tickets.FrontToBackPacket.Kind.ENTIRE, + front_to_back_ticket = interfaces.FrontToBackPacket( + test_operation_id, 0, interfaces.FrontToBackPacket.Kind.ENTIRE, test_method, interfaces.ServicedSubscription.Kind.FULL, None, test_front_to_back_datum, _TIMEOUT) rear_link.accept_front_to_back_ticket(front_to_back_ticket) @@ -153,7 +152,7 @@ class RoundTripTest(unittest.TestCase): with test_fore_link.condition: while (not test_fore_link.tickets or test_fore_link.tickets[-1].kind is not - tickets.BackToFrontPacket.Kind.COMPLETION): + interfaces.BackToFrontPacket.Kind.COMPLETION): test_fore_link.condition.wait() rear_link.stop() @@ -183,14 +182,14 @@ class RoundTripTest(unittest.TestCase): else: response = None terminal = front_to_back_ticket.kind in ( - tickets.FrontToBackPacket.Kind.COMPLETION, - tickets.FrontToBackPacket.Kind.ENTIRE) + interfaces.FrontToBackPacket.Kind.COMPLETION, + interfaces.FrontToBackPacket.Kind.ENTIRE) if response is not None or terminal: if terminal: - kind = tickets.BackToFrontPacket.Kind.COMPLETION + kind = interfaces.BackToFrontPacket.Kind.COMPLETION else: - kind = tickets.BackToFrontPacket.Kind.CONTINUATION - back_to_front_ticket = tickets.BackToFrontPacket( + kind = interfaces.BackToFrontPacket.Kind.CONTINUATION + back_to_front_ticket = interfaces.BackToFrontPacket( front_to_back_ticket.operation_id, rear_sequence_number[0], kind, response) rear_sequence_number[0] += 1 @@ -213,22 +212,23 @@ class RoundTripTest(unittest.TestCase): test_fore_link.join_rear_link(rear_link) rear_link.start() - commencement_ticket = tickets.FrontToBackPacket( - test_operation_id, 0, tickets.FrontToBackPacket.Kind.COMMENCEMENT, - test_method, interfaces.ServicedSubscription.Kind.FULL, None, None, + commencement_ticket = interfaces.FrontToBackPacket( + test_operation_id, 0, + interfaces.FrontToBackPacket.Kind.COMMENCEMENT, test_method, + interfaces.ServicedSubscription.Kind.FULL, None, None, _TIMEOUT) fore_sequence_number = 1 rear_link.accept_front_to_back_ticket(commencement_ticket) for request in scenario.requests(): - continuation_ticket = tickets.FrontToBackPacket( + continuation_ticket = interfaces.FrontToBackPacket( test_operation_id, fore_sequence_number, - tickets.FrontToBackPacket.Kind.CONTINUATION, None, None, None, + interfaces.FrontToBackPacket.Kind.CONTINUATION, None, None, None, request, None) fore_sequence_number += 1 rear_link.accept_front_to_back_ticket(continuation_ticket) - completion_ticket = tickets.FrontToBackPacket( + completion_ticket = interfaces.FrontToBackPacket( test_operation_id, fore_sequence_number, - tickets.FrontToBackPacket.Kind.COMPLETION, None, None, None, None, + interfaces.FrontToBackPacket.Kind.COMPLETION, None, None, None, None, None) fore_sequence_number += 1 rear_link.accept_front_to_back_ticket(completion_ticket) @@ -236,7 +236,7 @@ class RoundTripTest(unittest.TestCase): with test_fore_link.condition: while (not test_fore_link.tickets or test_fore_link.tickets[-1].kind is not - tickets.BackToFrontPacket.Kind.COMPLETION): + interfaces.BackToFrontPacket.Kind.COMPLETION): test_fore_link.condition.wait() rear_link.stop() diff --git a/src/python/src/grpc/_adapter/_lonely_rear_link_test.py b/src/python/src/grpc/_adapter/_lonely_rear_link_test.py index ead0b9eb38..4417f57e59 100644 --- a/src/python/src/grpc/_adapter/_lonely_rear_link_test.py +++ b/src/python/src/grpc/_adapter/_lonely_rear_link_test.py @@ -34,7 +34,6 @@ import unittest from grpc._adapter import _test_links from grpc._adapter import rear from grpc.framework.base import interfaces -from grpc.framework.base.packets import packets from grpc.framework.foundation import logging_pool _IDENTITY = lambda x: x @@ -68,7 +67,7 @@ class LonelyRearLinkTest(unittest.TestCase): rear_link.join_fore_link(fore_link) rear_link.start() - front_to_back_ticket = packets.FrontToBackPacket( + front_to_back_ticket = interfaces.FrontToBackPacket( test_operation_id, 0, front_to_back_ticket_kind, test_method, interfaces.ServicedSubscription.Kind.FULL, None, None, _TIMEOUT) rear_link.accept_front_to_back_ticket(front_to_back_ticket) @@ -77,7 +76,7 @@ class LonelyRearLinkTest(unittest.TestCase): while True: if (fore_link.tickets and fore_link.tickets[-1].kind is not - packets.BackToFrontPacket.Kind.CONTINUATION): + interfaces.BackToFrontPacket.Kind.CONTINUATION): break fore_link.condition.wait() @@ -86,15 +85,15 @@ class LonelyRearLinkTest(unittest.TestCase): with fore_link.condition: self.assertIsNot( fore_link.tickets[-1].kind, - packets.BackToFrontPacket.Kind.COMPLETION) + interfaces.BackToFrontPacket.Kind.COMPLETION) def testLonelyClientCommencementPacket(self): self._perform_lonely_client_test_with_ticket_kind( - packets.FrontToBackPacket.Kind.COMMENCEMENT) + interfaces.FrontToBackPacket.Kind.COMMENCEMENT) def testLonelyClientEntirePacket(self): self._perform_lonely_client_test_with_ticket_kind( - packets.FrontToBackPacket.Kind.ENTIRE) + interfaces.FrontToBackPacket.Kind.ENTIRE) if __name__ == '__main__': diff --git a/src/python/src/grpc/_adapter/_test_links.py b/src/python/src/grpc/_adapter/_test_links.py index ac0d6e20b6..86c7e61b17 100644 --- a/src/python/src/grpc/_adapter/_test_links.py +++ b/src/python/src/grpc/_adapter/_test_links.py @@ -31,7 +31,7 @@ import threading -from grpc.framework.base.packets import interfaces +from grpc.framework.base import interfaces class ForeLink(interfaces.ForeLink): diff --git a/src/python/src/grpc/_adapter/fore.py b/src/python/src/grpc/_adapter/fore.py index 16e5a2018c..85b1359e84 100644 --- a/src/python/src/grpc/_adapter/fore.py +++ b/src/python/src/grpc/_adapter/fore.py @@ -36,10 +36,8 @@ import time from grpc._adapter import _common from grpc._adapter import _low -from grpc.framework.base import interfaces -from grpc.framework.base.packets import interfaces as ticket_interfaces -from grpc.framework.base.packets import null -from grpc.framework.base.packets import packets as tickets +from grpc.framework.base import interfaces as base_interfaces +from grpc.framework.base import null from grpc.framework.foundation import activated from grpc.framework.foundation import logging_pool @@ -69,7 +67,7 @@ def _status(call, rpc_state): rpc_state.write.low = _LowWrite.CLOSED -class ForeLink(ticket_interfaces.ForeLink, activated.Activated): +class ForeLink(base_interfaces.ForeLink, activated.Activated): """A service-side bridge between RPC Framework and the C-ish _low code.""" def __init__( @@ -127,9 +125,9 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated): self._request_deserializers[method], self._response_serializers[method]) - ticket = tickets.FrontToBackPacket( - call, 0, tickets.FrontToBackPacket.Kind.COMMENCEMENT, method, - interfaces.ServicedSubscription.Kind.FULL, None, None, + ticket = base_interfaces.FrontToBackPacket( + call, 0, base_interfaces.FrontToBackPacket.Kind.COMMENCEMENT, method, + base_interfaces.ServicedSubscription.Kind.FULL, None, None, service_acceptance.deadline - time.time()) self._rear_link.accept_front_to_back_ticket(ticket) @@ -145,14 +143,16 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated): sequence_number = rpc_state.sequence_number rpc_state.sequence_number += 1 if event.bytes is None: - ticket = tickets.FrontToBackPacket( - call, sequence_number, tickets.FrontToBackPacket.Kind.COMPLETION, - None, None, None, None, None) + ticket = base_interfaces.FrontToBackPacket( + call, sequence_number, + base_interfaces.FrontToBackPacket.Kind.COMPLETION, None, None, None, + None, None) else: call.read(call) - ticket = tickets.FrontToBackPacket( - call, sequence_number, tickets.FrontToBackPacket.Kind.CONTINUATION, - None, None, None, rpc_state.deserializer(event.bytes), None) + ticket = base_interfaces.FrontToBackPacket( + call, sequence_number, + base_interfaces.FrontToBackPacket.Kind.CONTINUATION, None, None, + None, rpc_state.deserializer(event.bytes), None) self._rear_link.accept_front_to_back_ticket(ticket) @@ -180,10 +180,10 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated): sequence_number = rpc_state.sequence_number rpc_state.sequence_number += 1 - ticket = tickets.FrontToBackPacket( + ticket = base_interfaces.FrontToBackPacket( call, sequence_number, - tickets.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, None, None, - None, None, None) + base_interfaces.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, None, + None, None, None, None) self._rear_link.accept_front_to_back_ticket(ticket) def _on_finish_event(self, event): @@ -200,19 +200,21 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated): sequence_number = rpc_state.sequence_number rpc_state.sequence_number += 1 if code is _low.Code.CANCELLED: - ticket = tickets.FrontToBackPacket( - call, sequence_number, tickets.FrontToBackPacket.Kind.CANCELLATION, - None, None, None, None, None) + ticket = base_interfaces.FrontToBackPacket( + call, sequence_number, + base_interfaces.FrontToBackPacket.Kind.CANCELLATION, None, None, + None, None, None) elif code is _low.Code.EXPIRED: - ticket = tickets.FrontToBackPacket( - call, sequence_number, tickets.FrontToBackPacket.Kind.EXPIRATION, - None, None, None, None, None) + ticket = base_interfaces.FrontToBackPacket( + call, sequence_number, + base_interfaces.FrontToBackPacket.Kind.EXPIRATION, None, None, None, + None, None) else: # TODO(nathaniel): Better mapping of codes to ticket-categories - ticket = tickets.FrontToBackPacket( + ticket = base_interfaces.FrontToBackPacket( call, sequence_number, - tickets.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, None, None, - None, None, None) + base_interfaces.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, None, + None, None, None, None) self._rear_link.accept_front_to_back_ticket(ticket) def _spin(self, completion_queue, server): @@ -268,7 +270,7 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated): self._rpc_states.pop(call, None) def join_rear_link(self, rear_link): - """See ticket_interfaces.ForeLink.join_rear_link for specification.""" + """See base_interfaces.ForeLink.join_rear_link for specification.""" self._rear_link = null.NULL_REAR_LINK if rear_link is None else rear_link def _start(self): @@ -348,14 +350,14 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated): return self._port def accept_back_to_front_ticket(self, ticket): - """See ticket_interfaces.ForeLink.accept_back_to_front_ticket for spec.""" + """See base_interfaces.ForeLink.accept_back_to_front_ticket for spec.""" with self._condition: if self._server is None: return - if ticket.kind is tickets.BackToFrontPacket.Kind.CONTINUATION: + if ticket.kind is base_interfaces.BackToFrontPacket.Kind.CONTINUATION: self._continue(ticket.operation_id, ticket.payload) - elif ticket.kind is tickets.BackToFrontPacket.Kind.COMPLETION: + elif ticket.kind is base_interfaces.BackToFrontPacket.Kind.COMPLETION: self._complete(ticket.operation_id, ticket.payload) else: self._cancel(ticket.operation_id) diff --git a/src/python/src/grpc/_adapter/rear.py b/src/python/src/grpc/_adapter/rear.py index eee008e4df..f2d9aae8ab 100644 --- a/src/python/src/grpc/_adapter/rear.py +++ b/src/python/src/grpc/_adapter/rear.py @@ -36,9 +36,8 @@ import time from grpc._adapter import _common from grpc._adapter import _low -from grpc.framework.base.packets import interfaces as ticket_interfaces -from grpc.framework.base.packets import null -from grpc.framework.base.packets import packets as tickets +from grpc.framework.base import interfaces as base_interfaces +from grpc.framework.base import null from grpc.framework.foundation import activated from grpc.framework.foundation import logging_pool @@ -88,7 +87,7 @@ def _write(operation_id, call, outstanding, write_state, serialized_payload): raise ValueError('Write attempted after writes completed!') -class RearLink(ticket_interfaces.RearLink, activated.Activated): +class RearLink(base_interfaces.RearLink, activated.Activated): """An invocation-side bridge between RPC Framework and the C-ish _low code.""" def __init__( @@ -152,9 +151,9 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated): else: logging.error('RPC write not accepted! Event: %s', (event,)) rpc_state.active = False - ticket = tickets.BackToFrontPacket( + ticket = base_interfaces.BackToFrontPacket( operation_id, rpc_state.common.sequence_number, - tickets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, None) + base_interfaces.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, None) rpc_state.common.sequence_number += 1 self._fore_link.accept_back_to_front_ticket(ticket) @@ -163,9 +162,9 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated): rpc_state.call.read(operation_id) rpc_state.outstanding.add(_low.Event.Kind.READ_ACCEPTED) - ticket = tickets.BackToFrontPacket( + ticket = base_interfaces.BackToFrontPacket( operation_id, rpc_state.common.sequence_number, - tickets.BackToFrontPacket.Kind.CONTINUATION, + base_interfaces.BackToFrontPacket.Kind.CONTINUATION, rpc_state.common.deserializer(event.bytes)) rpc_state.common.sequence_number += 1 self._fore_link.accept_back_to_front_ticket(ticket) @@ -174,9 +173,9 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated): if not event.complete_accepted: logging.error('RPC complete not accepted! Event: %s', (event,)) rpc_state.active = False - ticket = tickets.BackToFrontPacket( + ticket = base_interfaces.BackToFrontPacket( operation_id, rpc_state.common.sequence_number, - tickets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, None) + base_interfaces.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, None) rpc_state.common.sequence_number += 1 self._fore_link.accept_back_to_front_ticket(ticket) @@ -189,14 +188,14 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated): """Handle termination of an RPC.""" # TODO(nathaniel): Cover all statuses. if event.status.code is _low.Code.OK: - kind = tickets.BackToFrontPacket.Kind.COMPLETION + kind = base_interfaces.BackToFrontPacket.Kind.COMPLETION elif event.status.code is _low.Code.CANCELLED: - kind = tickets.BackToFrontPacket.Kind.CANCELLATION + kind = base_interfaces.BackToFrontPacket.Kind.CANCELLATION elif event.status.code is _low.Code.EXPIRED: - kind = tickets.BackToFrontPacket.Kind.EXPIRATION + kind = base_interfaces.BackToFrontPacket.Kind.EXPIRATION else: - kind = tickets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE - ticket = tickets.BackToFrontPacket( + kind = base_interfaces.BackToFrontPacket.Kind.TRANSMISSION_FAILURE + ticket = base_interfaces.BackToFrontPacket( operation_id, rpc_state.common.sequence_number, kind, None) rpc_state.common.sequence_number += 1 self._fore_link.accept_back_to_front_ticket(ticket) @@ -317,7 +316,7 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated): rpc_state.active = False def join_fore_link(self, fore_link): - """See ticket_interfaces.RearLink.join_fore_link for specification.""" + """See base_interfaces.RearLink.join_fore_link for specification.""" with self._condition: self._fore_link = null.NULL_FORE_LINK if fore_link is None else fore_link @@ -366,22 +365,22 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated): self._stop() def accept_front_to_back_ticket(self, ticket): - """See ticket_interfaces.RearLink.accept_front_to_back_ticket for spec.""" + """See base_interfaces.RearLink.accept_front_to_back_ticket for spec.""" with self._condition: if self._completion_queue is None: return - if ticket.kind is tickets.FrontToBackPacket.Kind.COMMENCEMENT: + if ticket.kind is base_interfaces.FrontToBackPacket.Kind.COMMENCEMENT: self._commence( ticket.operation_id, ticket.name, ticket.payload, ticket.timeout) - elif ticket.kind is tickets.FrontToBackPacket.Kind.CONTINUATION: + elif ticket.kind is base_interfaces.FrontToBackPacket.Kind.CONTINUATION: self._continue(ticket.operation_id, ticket.payload) - elif ticket.kind is tickets.FrontToBackPacket.Kind.COMPLETION: + elif ticket.kind is base_interfaces.FrontToBackPacket.Kind.COMPLETION: self._complete(ticket.operation_id, ticket.payload) - elif ticket.kind is tickets.FrontToBackPacket.Kind.ENTIRE: + elif ticket.kind is base_interfaces.FrontToBackPacket.Kind.ENTIRE: self._entire( ticket.operation_id, ticket.name, ticket.payload, ticket.timeout) - elif ticket.kind is tickets.FrontToBackPacket.Kind.CANCELLATION: + elif ticket.kind is base_interfaces.FrontToBackPacket.Kind.CANCELLATION: self._cancel(ticket.operation_id) else: # NOTE(nathaniel): All other categories are treated as cancellation. diff --git a/src/python/src/grpc/early_adopter/implementations.py b/src/python/src/grpc/early_adopter/implementations.py index 7c50d7d8b2..9cadb58d0f 100644 --- a/src/python/src/grpc/early_adopter/implementations.py +++ b/src/python/src/grpc/early_adopter/implementations.py @@ -36,8 +36,8 @@ from grpc._adapter import rear as _rear from grpc.early_adopter import _face_utilities from grpc.early_adopter import _reexport from grpc.early_adopter import interfaces +from grpc.framework.base import implementations as _base_implementations from grpc.framework.base import util as _base_utilities -from grpc.framework.base.packets import implementations as _tickets_implementations from grpc.framework.face import implementations as _face_implementations from grpc.framework.foundation import logging_pool @@ -66,7 +66,7 @@ class _Server(interfaces.Server): self._pool = logging_pool.pool(_THREAD_POOL_SIZE) servicer = _face_implementations.servicer( self._pool, self._breakdown.implementations, None) - self._back = _tickets_implementations.back( + 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( @@ -134,7 +134,7 @@ class _Stub(interfaces.Stub): with self._lock: if self._pool is None: self._pool = logging_pool.pool(_THREAD_POOL_SIZE) - self._front = _tickets_implementations.front( + self._front = _base_implementations.front_link( self._pool, self._pool, self._pool) self._rear_link = _rear.RearLink( self._host, self._port, self._pool, diff --git a/src/python/src/grpc/framework/base/packets/_cancellation.py b/src/python/src/grpc/framework/base/_cancellation.py similarity index 89% rename from src/python/src/grpc/framework/base/packets/_cancellation.py rename to src/python/src/grpc/framework/base/_cancellation.py index 4a0ced1440..ffbc90668f 100644 --- a/src/python/src/grpc/framework/base/packets/_cancellation.py +++ b/src/python/src/grpc/framework/base/_cancellation.py @@ -29,9 +29,8 @@ """State and behavior for operation cancellation.""" -from grpc.framework.base import interfaces as base_interfaces -from grpc.framework.base.packets import _interfaces -from grpc.framework.base.packets import packets +from grpc.framework.base import _interfaces +from grpc.framework.base import interfaces class CancellationManager(_interfaces.CancellationManager): @@ -59,7 +58,7 @@ class CancellationManager(_interfaces.CancellationManager): def cancel(self): """See _interfaces.CancellationManager.cancel for specification.""" with self._lock: - self._termination_manager.abort(base_interfaces.Outcome.CANCELLED) - self._transmission_manager.abort(base_interfaces.Outcome.CANCELLED) + self._termination_manager.abort(interfaces.Outcome.CANCELLED) + self._transmission_manager.abort(interfaces.Outcome.CANCELLED) self._ingestion_manager.abort() self._expiration_manager.abort() diff --git a/src/python/src/grpc/framework/base/packets/_constants.py b/src/python/src/grpc/framework/base/_constants.py similarity index 100% rename from src/python/src/grpc/framework/base/packets/_constants.py rename to src/python/src/grpc/framework/base/_constants.py diff --git a/src/python/src/grpc/framework/base/packets/_context.py b/src/python/src/grpc/framework/base/_context.py similarity index 86% rename from src/python/src/grpc/framework/base/packets/_context.py rename to src/python/src/grpc/framework/base/_context.py index 45241c639e..d84871d639 100644 --- a/src/python/src/grpc/framework/base/packets/_context.py +++ b/src/python/src/grpc/framework/base/_context.py @@ -32,12 +32,12 @@ import time # _interfaces is referenced from specification in this module. -from grpc.framework.base import interfaces as base_interfaces -from grpc.framework.base.packets import _interfaces # pylint: disable=unused-import +from grpc.framework.base import interfaces +from grpc.framework.base import _interfaces # pylint: disable=unused-import -class OperationContext(base_interfaces.OperationContext): - """An implementation of base_interfaces.OperationContext.""" +class OperationContext(interfaces.OperationContext): + """An implementation of interfaces.OperationContext.""" def __init__( self, lock, operation_id, local_failure, termination_manager, @@ -47,8 +47,8 @@ class OperationContext(base_interfaces.OperationContext): Args: lock: The operation-wide lock. operation_id: An object identifying the operation. - local_failure: Whichever one of base_interfaces.Outcome.SERVICED_FAILURE - or base_interfaces.Outcome.SERVICER_FAILURE describes local failure of + local_failure: Whichever one of interfaces.Outcome.SERVICED_FAILURE or + interfaces.Outcome.SERVICER_FAILURE describes local failure of customer code. termination_manager: The _interfaces.TerminationManager for the operation. transmission_manager: The _interfaces.TransmissionManager for the @@ -75,12 +75,12 @@ class OperationContext(base_interfaces.OperationContext): self._expiration_manager = expiration_manager def is_active(self): - """See base_interfaces.OperationContext.is_active for specification.""" + """See interfaces.OperationContext.is_active for specification.""" with self._lock: return self._termination_manager.is_active() def add_termination_callback(self, callback): - """See base_interfaces.OperationContext.add_termination_callback.""" + """See interfaces.OperationContext.add_termination_callback.""" with self._lock: self._termination_manager.add_callback(callback) diff --git a/src/python/src/grpc/framework/base/packets/_emission.py b/src/python/src/grpc/framework/base/_emission.py similarity index 89% rename from src/python/src/grpc/framework/base/packets/_emission.py rename to src/python/src/grpc/framework/base/_emission.py index cfc9e40a24..1829669a72 100644 --- a/src/python/src/grpc/framework/base/packets/_emission.py +++ b/src/python/src/grpc/framework/base/_emission.py @@ -29,8 +29,8 @@ """State and behavior for handling emitted values.""" -from grpc.framework.base import interfaces as base_interfaces -from grpc.framework.base.packets import _interfaces +from grpc.framework.base import interfaces +from grpc.framework.base import _interfaces class _EmissionManager(_interfaces.EmissionManager): @@ -42,10 +42,9 @@ class _EmissionManager(_interfaces.EmissionManager): Args: lock: The operation-wide lock. - failure_outcome: Whichever one of - base_interfaces.Outcome.SERVICED_FAILURE or - base_interfaces.Outcome.SERVICER_FAILURE describes this object's - methods being called inappropriately by customer code. + failure_outcome: Whichever one of interfaces.Outcome.SERVICED_FAILURE or + interfaces.Outcome.SERVICER_FAILURE describes this object's methods + being called inappropriately by customer code. termination_manager: The _interfaces.TerminationManager for the operation. transmission_manager: The _interfaces.TransmissionManager for the operation. @@ -106,7 +105,7 @@ def front_emission_manager(lock, termination_manager, transmission_manager): An _interfaces.EmissionManager appropriate for front-side use. """ return _EmissionManager( - lock, base_interfaces.Outcome.SERVICED_FAILURE, termination_manager, + lock, interfaces.Outcome.SERVICED_FAILURE, termination_manager, transmission_manager) @@ -122,5 +121,5 @@ def back_emission_manager(lock, termination_manager, transmission_manager): An _interfaces.EmissionManager appropriate for back-side use. """ return _EmissionManager( - lock, base_interfaces.Outcome.SERVICER_FAILURE, termination_manager, + lock, interfaces.Outcome.SERVICER_FAILURE, termination_manager, transmission_manager) diff --git a/src/python/src/grpc/framework/base/packets/_ends.py b/src/python/src/grpc/framework/base/_ends.py similarity index 86% rename from src/python/src/grpc/framework/base/packets/_ends.py rename to src/python/src/grpc/framework/base/_ends.py index 614d1f666e..e774b49df3 100644 --- a/src/python/src/grpc/framework/base/packets/_ends.py +++ b/src/python/src/grpc/framework/base/_ends.py @@ -27,32 +27,30 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""Implementations of Fronts and Backs.""" +"""Implementations of FrontLinks and BackLinks.""" import collections import threading import uuid -# _interfaces and packets are referenced from specification in this module. -from grpc.framework.base import interfaces as base_interfaces -from grpc.framework.base.packets import _cancellation -from grpc.framework.base.packets import _context -from grpc.framework.base.packets import _emission -from grpc.framework.base.packets import _expiration -from grpc.framework.base.packets import _ingestion -from grpc.framework.base.packets import _interfaces # pylint: disable=unused-import -from grpc.framework.base.packets import _reception -from grpc.framework.base.packets import _termination -from grpc.framework.base.packets import _transmission -from grpc.framework.base.packets import interfaces -from grpc.framework.base.packets import packets # pylint: disable=unused-import +# _interfaces is referenced from specification in this module. +from grpc.framework.base import _cancellation +from grpc.framework.base import _context +from grpc.framework.base import _emission +from grpc.framework.base import _expiration +from grpc.framework.base import _ingestion +from grpc.framework.base import _interfaces # pylint: disable=unused-import +from grpc.framework.base import _reception +from grpc.framework.base import _termination +from grpc.framework.base import _transmission +from grpc.framework.base import interfaces from grpc.framework.foundation import callable_util _IDLE_ACTION_EXCEPTION_LOG_MESSAGE = 'Exception calling idle action!' -class _EasyOperation(base_interfaces.Operation): - """A trivial implementation of base_interfaces.Operation.""" +class _EasyOperation(interfaces.Operation): + """A trivial implementation of interfaces.Operation.""" def __init__(self, emission_manager, context, cancellation_manager): """Constructor. @@ -60,7 +58,7 @@ class _EasyOperation(base_interfaces.Operation): Args: emission_manager: The _interfaces.EmissionManager for the operation that will accept values emitted by customer code. - context: The base_interfaces.OperationContext for use by the customer + context: The interfaces.OperationContext for use by the customer during the operation. cancellation_manager: The _interfaces.CancellationManager for the operation. @@ -88,7 +86,7 @@ class _Endlette(object): # indicates an in-progress fire-and-forget operation for which the customer # has chosen to ignore results. self._operations = {} - self._stats = {outcome: 0 for outcome in base_interfaces.Outcome} + self._stats = {outcome: 0 for outcome in interfaces.Outcome} self._idle_actions = [] def terminal_action(self, operation_id): @@ -152,9 +150,9 @@ def _front_operate( """Constructs objects necessary for front-side operation management. Args: - callback: A callable that accepts packets.FrontToBackPackets and delivers - them to the other side of the operation. Execution of this callable may - take any arbitrary length of time. + callback: A callable that accepts interfaces.FrontToBackPackets and + delivers them to the other side of the operation. Execution of this + callable may take any arbitrary length of time. work_pool: A thread pool in which to execute customer code. transmission_pool: A thread pool to use for transmitting to the other side of the operation. @@ -169,7 +167,7 @@ def _front_operate( complete: A boolean indicating whether or not additional payloads will be supplied by the customer. timeout: A length of time in seconds to allow for the operation. - subscription: A base_interfaces.ServicedSubscription describing the + subscription: A interfaces.ServicedSubscription describing the customer's interest in the results of the operation. trace_id: A uuid.UUID identifying a set of related operations to which this operation belongs. May be None. @@ -188,7 +186,7 @@ def _front_operate( lock, transmission_pool, callback, operation_id, name, subscription.kind, trace_id, timeout, termination_manager) operation_context = _context.OperationContext( - lock, operation_id, base_interfaces.Outcome.SERVICED_FAILURE, + lock, operation_id, interfaces.Outcome.SERVICED_FAILURE, termination_manager, transmission_manager) emission_manager = _emission.front_emission_manager( lock, termination_manager, transmission_manager) @@ -216,7 +214,7 @@ def _front_operate( transmission_manager.inmit(payload, complete) - if subscription.kind is base_interfaces.ServicedSubscription.Kind.NONE: + if subscription.kind is interfaces.ServicedSubscription.Kind.NONE: returned_reception_manager = None else: returned_reception_manager = reception_manager @@ -226,8 +224,8 @@ def _front_operate( cancellation_manager) -class Front(interfaces.Front): - """An implementation of interfaces.Front.""" +class FrontLink(interfaces.FrontLink): + """An implementation of interfaces.FrontLink.""" def __init__(self, work_pool, transmission_pool, utility_pool): """Constructor. @@ -252,16 +250,16 @@ class Front(interfaces.Front): self._callback = rear_link.accept_front_to_back_ticket def operation_stats(self): - """See base_interfaces.End.operation_stats for specification.""" + """See interfaces.End.operation_stats for specification.""" return self._endlette.operation_stats() def add_idle_action(self, action): - """See base_interfaces.End.add_idle_action for specification.""" + """See interfaces.End.add_idle_action for specification.""" self._endlette.add_idle_action(action) def operate( self, name, payload, complete, timeout, subscription, trace_id): - """See base_interfaces.Front.operate for specification.""" + """See interfaces.Front.operate for specification.""" operation_id = uuid.uuid4() with self._endlette: management = _front_operate( @@ -291,16 +289,16 @@ def _back_operate( Args: servicer: An interfaces.Servicer for servicing operations. - callback: A callable that accepts packets.BackToFrontPackets and delivers - them to the other side of the operation. Execution of this callable may - take any arbitrary length of time. + callback: A callable that accepts interfaces.BackToFrontPackets and + delivers them to the other side of the operation. Execution of this + callable may take any arbitrary length of time. work_pool: A thread pool in which to execute customer code. transmission_pool: A thread pool to use for transmitting to the other side of the operation. utility_pool: A thread pool for utility tasks. termination_action: A no-arg behavior to be called upon operation completion. - ticket: The first packets.FrontToBackPacket received for the operation. + ticket: The first interfaces.FrontToBackPacket received for the operation. default_timeout: A length of time in seconds to be used as the default time alloted for a single operation. maximum_timeout: A length of time in seconds to be used as the maximum @@ -317,7 +315,7 @@ def _back_operate( lock, transmission_pool, callback, ticket.operation_id, termination_manager, ticket.subscription) operation_context = _context.OperationContext( - lock, ticket.operation_id, base_interfaces.Outcome.SERVICER_FAILURE, + lock, ticket.operation_id, interfaces.Outcome.SERVICER_FAILURE, termination_manager, transmission_manager) emission_manager = _emission.back_emission_manager( lock, termination_manager, transmission_manager) @@ -345,8 +343,8 @@ def _back_operate( return reception_manager -class Back(interfaces.Back): - """An implementation of interfaces.Back.""" +class BackLink(interfaces.BackLink): + """An implementation of interfaces.BackLink.""" def __init__( self, servicer, work_pool, transmission_pool, utility_pool, @@ -393,9 +391,9 @@ class Back(interfaces.Back): reception_manager.receive_packet(ticket) def operation_stats(self): - """See base_interfaces.End.operation_stats for specification.""" + """See interfaces.End.operation_stats for specification.""" return self._endlette.operation_stats() def add_idle_action(self, action): - """See base_interfaces.End.add_idle_action for specification.""" + """See interfaces.End.add_idle_action for specification.""" self._endlette.add_idle_action(action) diff --git a/src/python/src/grpc/framework/base/packets/_expiration.py b/src/python/src/grpc/framework/base/_expiration.py similarity index 95% rename from src/python/src/grpc/framework/base/packets/_expiration.py rename to src/python/src/grpc/framework/base/_expiration.py index a9ecaeaa63..17acbef4c1 100644 --- a/src/python/src/grpc/framework/base/packets/_expiration.py +++ b/src/python/src/grpc/framework/base/_expiration.py @@ -31,8 +31,8 @@ import time -from grpc.framework.base import interfaces as base_interfaces -from grpc.framework.base.packets import _interfaces +from grpc.framework.base import _interfaces +from grpc.framework.base import interfaces from grpc.framework.foundation import later @@ -73,8 +73,8 @@ class _ExpirationManager(_interfaces.ExpirationManager): with self._lock: if self._future is not None and index == self._index: self._future = None - self._termination_manager.abort(base_interfaces.Outcome.EXPIRED) - self._transmission_manager.abort(base_interfaces.Outcome.EXPIRED) + self._termination_manager.abort(interfaces.Outcome.EXPIRED) + self._transmission_manager.abort(interfaces.Outcome.EXPIRED) self._ingestion_manager.abort() def start(self): diff --git a/src/python/src/grpc/framework/base/packets/_ingestion.py b/src/python/src/grpc/framework/base/_ingestion.py similarity index 99% rename from src/python/src/grpc/framework/base/packets/_ingestion.py rename to src/python/src/grpc/framework/base/_ingestion.py index c5c08fd98e..06d5b92f0b 100644 --- a/src/python/src/grpc/framework/base/packets/_ingestion.py +++ b/src/python/src/grpc/framework/base/_ingestion.py @@ -32,11 +32,10 @@ import abc import collections +from grpc.framework.base import _constants +from grpc.framework.base import _interfaces from grpc.framework.base import exceptions from grpc.framework.base import interfaces -from grpc.framework.base.packets import _constants -from grpc.framework.base.packets import _interfaces -from grpc.framework.base.packets import packets from grpc.framework.foundation import abandonment from grpc.framework.foundation import callable_util from grpc.framework.foundation import stream diff --git a/src/python/src/grpc/framework/base/packets/_interfaces.py b/src/python/src/grpc/framework/base/_interfaces.py similarity index 93% rename from src/python/src/grpc/framework/base/packets/_interfaces.py rename to src/python/src/grpc/framework/base/_interfaces.py index 64184bdf7c..801420e4ac 100644 --- a/src/python/src/grpc/framework/base/packets/_interfaces.py +++ b/src/python/src/grpc/framework/base/_interfaces.py @@ -31,9 +31,8 @@ import abc -# base_interfaces and packets are referenced from specification in this module. -from grpc.framework.base import interfaces as base_interfaces # pylint: disable=unused-import -from grpc.framework.base.packets import packets # pylint: disable=unused-import +# interfaces is referenced from specification in this module. +from grpc.framework.base import interfaces # pylint: disable=unused-import from grpc.framework.foundation import stream @@ -63,7 +62,7 @@ class TerminationManager(object): immediately. Args: - callback: A callable that will be passed a base_interfaces.Outcome value. + callback: A callable that will be passed an interfaces.Outcome value. """ raise NotImplementedError() @@ -87,7 +86,7 @@ class TerminationManager(object): """Indicates that the operation must abort for the indicated reason. Args: - outcome: A base_interfaces.Outcome indicating operation abortion. + outcome: An interfaces.Outcome indicating operation abortion. """ raise NotImplementedError() @@ -113,7 +112,7 @@ class TransmissionManager(object): """Indicates that the operation has aborted for the indicated reason. Args: - outcome: A base_interfaces.Outcome indicating operation abortion. + outcome: An interfaces.Outcome indicating operation abortion. """ raise NotImplementedError() @@ -256,7 +255,7 @@ class ReceptionManager(object): """Handle a packet from the other side of the operation. Args: - packet: A packets.BackToFrontPacket or packets.FrontToBackPacket + packet: An interfaces.BackToFrontPacket or interfaces.FrontToBackPacket appropriate to this end of the operation and this object. """ raise NotImplementedError() diff --git a/src/python/src/grpc/framework/base/packets/_reception.py b/src/python/src/grpc/framework/base/_reception.py similarity index 85% rename from src/python/src/grpc/framework/base/packets/_reception.py rename to src/python/src/grpc/framework/base/_reception.py index ef10c7f8fe..f523800d86 100644 --- a/src/python/src/grpc/framework/base/packets/_reception.py +++ b/src/python/src/grpc/framework/base/_reception.py @@ -31,13 +31,12 @@ import abc -from grpc.framework.base import interfaces as base_interfaces -from grpc.framework.base.packets import _interfaces -from grpc.framework.base.packets import packets +from grpc.framework.base import interfaces +from grpc.framework.base import _interfaces _INITIAL_FRONT_TO_BACK_PACKET_KINDS = ( - packets.FrontToBackPacket.Kind.COMMENCEMENT, - packets.FrontToBackPacket.Kind.ENTIRE, + interfaces.FrontToBackPacket.Kind.COMMENCEMENT, + interfaces.FrontToBackPacket.Kind.ENTIRE, ) @@ -94,9 +93,9 @@ def _abort_if_abortive( Args: packet: A just-arrived packet. - abortive: A callable that takes a packet and returns a - base_interfaces.Outcome indicating that the operation should be aborted - or None indicating that the operation should not be aborted. + abortive: A callable that takes a packet and returns an interfaces.Outcome + indicating that the operation should be aborted or None indicating that + the operation should not be aborted. termination_manager: The operation's _interfaces.TerminationManager. transmission_manager: The operation's _interfaces.TransmissionManager. ingestion_manager: The operation's _interfaces.IngestionManager. @@ -120,7 +119,7 @@ def _reception_failure( expiration_manager): """Aborts the operation with an indication of reception failure.""" _abort( - base_interfaces.Outcome.RECEPTION_FAILURE, termination_manager, + interfaces.Outcome.RECEPTION_FAILURE, termination_manager, transmission_manager, ingestion_manager, expiration_manager) @@ -153,22 +152,22 @@ class _BackReceiver(_Receiver): packet: A just-arrived packet. Returns: - A base_interfaces.Outcome value describing operation abortion if the + An interfaces.Outcome value describing operation abortion if the packet is abortive or None if the packet is not abortive. """ - if packet.kind is packets.FrontToBackPacket.Kind.CANCELLATION: - return base_interfaces.Outcome.CANCELLED - elif packet.kind is packets.FrontToBackPacket.Kind.EXPIRATION: - return base_interfaces.Outcome.EXPIRED - elif packet.kind is packets.FrontToBackPacket.Kind.SERVICED_FAILURE: - return base_interfaces.Outcome.SERVICED_FAILURE - elif packet.kind is packets.FrontToBackPacket.Kind.RECEPTION_FAILURE: - return base_interfaces.Outcome.SERVICED_FAILURE + if packet.kind is interfaces.FrontToBackPacket.Kind.CANCELLATION: + return interfaces.Outcome.CANCELLED + elif packet.kind is interfaces.FrontToBackPacket.Kind.EXPIRATION: + return interfaces.Outcome.EXPIRED + elif packet.kind is interfaces.FrontToBackPacket.Kind.SERVICED_FAILURE: + return interfaces.Outcome.SERVICED_FAILURE + elif packet.kind is interfaces.FrontToBackPacket.Kind.RECEPTION_FAILURE: + return interfaces.Outcome.SERVICED_FAILURE elif (packet.kind in _INITIAL_FRONT_TO_BACK_PACKET_KINDS and self._first_packet_seen): - return base_interfaces.Outcome.RECEPTION_FAILURE + return interfaces.Outcome.RECEPTION_FAILURE elif self._last_packet_seen: - return base_interfaces.Outcome.RECEPTION_FAILURE + return interfaces.Outcome.RECEPTION_FAILURE else: return None @@ -184,14 +183,14 @@ class _BackReceiver(_Receiver): if packet.timeout is not None: self._expiration_manager.change_timeout(packet.timeout) - if packet.kind is packets.FrontToBackPacket.Kind.COMMENCEMENT: + if packet.kind is interfaces.FrontToBackPacket.Kind.COMMENCEMENT: self._first_packet_seen = True self._ingestion_manager.start(packet.name) if packet.payload is not None: self._ingestion_manager.consume(packet.payload) - elif packet.kind is packets.FrontToBackPacket.Kind.CONTINUATION: + elif packet.kind is interfaces.FrontToBackPacket.Kind.CONTINUATION: self._ingestion_manager.consume(packet.payload) - elif packet.kind is packets.FrontToBackPacket.Kind.COMPLETION: + elif packet.kind is interfaces.FrontToBackPacket.Kind.COMPLETION: self._last_packet_seen = True if packet.payload is None: self._ingestion_manager.terminate() @@ -241,19 +240,19 @@ class _FrontReceiver(_Receiver): packet: A just-arrived packet. Returns: - A base_interfaces.Outcome value describing operation abortion if the - packet is abortive or None if the packet is not abortive. + An interfaces.Outcome value describing operation abortion if the packet + is abortive or None if the packet is not abortive. """ - if packet.kind is packets.BackToFrontPacket.Kind.CANCELLATION: - return base_interfaces.Outcome.CANCELLED - elif packet.kind is packets.BackToFrontPacket.Kind.EXPIRATION: - return base_interfaces.Outcome.EXPIRED - elif packet.kind is packets.BackToFrontPacket.Kind.SERVICER_FAILURE: - return base_interfaces.Outcome.SERVICER_FAILURE - elif packet.kind is packets.BackToFrontPacket.Kind.RECEPTION_FAILURE: - return base_interfaces.Outcome.SERVICER_FAILURE + if packet.kind is interfaces.BackToFrontPacket.Kind.CANCELLATION: + return interfaces.Outcome.CANCELLED + elif packet.kind is interfaces.BackToFrontPacket.Kind.EXPIRATION: + return interfaces.Outcome.EXPIRED + elif packet.kind is interfaces.BackToFrontPacket.Kind.SERVICER_FAILURE: + return interfaces.Outcome.SERVICER_FAILURE + elif packet.kind is interfaces.BackToFrontPacket.Kind.RECEPTION_FAILURE: + return interfaces.Outcome.SERVICER_FAILURE elif self._last_packet_seen: - return base_interfaces.Outcome.RECEPTION_FAILURE + return interfaces.Outcome.RECEPTION_FAILURE else: return None @@ -266,9 +265,9 @@ class _FrontReceiver(_Receiver): def receive(self, packet): """See _Receiver.receive for specification.""" - if packet.kind is packets.BackToFrontPacket.Kind.CONTINUATION: + if packet.kind is interfaces.BackToFrontPacket.Kind.CONTINUATION: self._ingestion_manager.consume(packet.payload) - elif packet.kind is packets.BackToFrontPacket.Kind.COMPLETION: + elif packet.kind is interfaces.BackToFrontPacket.Kind.COMPLETION: self._last_packet_seen = True if packet.payload is None: self._ingestion_manager.terminate() diff --git a/src/python/src/grpc/framework/base/packets/_termination.py b/src/python/src/grpc/framework/base/_termination.py similarity index 98% rename from src/python/src/grpc/framework/base/packets/_termination.py rename to src/python/src/grpc/framework/base/_termination.py index 6afba88fc4..ddcbc60293 100644 --- a/src/python/src/grpc/framework/base/packets/_termination.py +++ b/src/python/src/grpc/framework/base/_termination.py @@ -31,9 +31,9 @@ import enum +from grpc.framework.base import _constants +from grpc.framework.base import _interfaces from grpc.framework.base import interfaces -from grpc.framework.base.packets import _constants -from grpc.framework.base.packets import _interfaces from grpc.framework.foundation import callable_util _CALLBACK_EXCEPTION_LOG_MESSAGE = 'Exception calling termination callback!' diff --git a/src/python/src/grpc/framework/base/packets/_transmission.py b/src/python/src/grpc/framework/base/_transmission.py similarity index 91% rename from src/python/src/grpc/framework/base/packets/_transmission.py rename to src/python/src/grpc/framework/base/_transmission.py index 1b18204ec5..510ca11c61 100644 --- a/src/python/src/grpc/framework/base/packets/_transmission.py +++ b/src/python/src/grpc/framework/base/_transmission.py @@ -31,10 +31,9 @@ import abc +from grpc.framework.base import _constants +from grpc.framework.base import _interfaces from grpc.framework.base import interfaces -from grpc.framework.base.packets import _constants -from grpc.framework.base.packets import _interfaces -from grpc.framework.base.packets import packets from grpc.framework.foundation import callable_util _TRANSMISSION_EXCEPTION_LOG_MESSAGE = 'Exception during transmission!' @@ -49,32 +48,32 @@ _BACK_TO_FRONT_NO_TRANSMISSION_OUTCOMES = ( _ABORTION_OUTCOME_TO_FRONT_TO_BACK_PACKET_KIND = { interfaces.Outcome.CANCELLED: - packets.FrontToBackPacket.Kind.CANCELLATION, + interfaces.FrontToBackPacket.Kind.CANCELLATION, interfaces.Outcome.EXPIRED: - packets.FrontToBackPacket.Kind.EXPIRATION, + interfaces.FrontToBackPacket.Kind.EXPIRATION, interfaces.Outcome.RECEPTION_FAILURE: - packets.FrontToBackPacket.Kind.RECEPTION_FAILURE, + interfaces.FrontToBackPacket.Kind.RECEPTION_FAILURE, interfaces.Outcome.TRANSMISSION_FAILURE: - packets.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, + interfaces.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, interfaces.Outcome.SERVICED_FAILURE: - packets.FrontToBackPacket.Kind.SERVICED_FAILURE, + interfaces.FrontToBackPacket.Kind.SERVICED_FAILURE, interfaces.Outcome.SERVICER_FAILURE: - packets.FrontToBackPacket.Kind.SERVICER_FAILURE, + interfaces.FrontToBackPacket.Kind.SERVICER_FAILURE, } _ABORTION_OUTCOME_TO_BACK_TO_FRONT_PACKET_KIND = { interfaces.Outcome.CANCELLED: - packets.BackToFrontPacket.Kind.CANCELLATION, + interfaces.BackToFrontPacket.Kind.CANCELLATION, interfaces.Outcome.EXPIRED: - packets.BackToFrontPacket.Kind.EXPIRATION, + interfaces.BackToFrontPacket.Kind.EXPIRATION, interfaces.Outcome.RECEPTION_FAILURE: - packets.BackToFrontPacket.Kind.RECEPTION_FAILURE, + interfaces.BackToFrontPacket.Kind.RECEPTION_FAILURE, interfaces.Outcome.TRANSMISSION_FAILURE: - packets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, + interfaces.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, interfaces.Outcome.SERVICED_FAILURE: - packets.BackToFrontPacket.Kind.SERVICED_FAILURE, + interfaces.BackToFrontPacket.Kind.SERVICED_FAILURE, interfaces.Outcome.SERVICER_FAILURE: - packets.BackToFrontPacket.Kind.SERVICER_FAILURE, + interfaces.BackToFrontPacket.Kind.SERVICER_FAILURE, } @@ -141,18 +140,18 @@ class _FrontPacketizer(_Packetizer): """See _Packetizer.packetize for specification.""" if sequence_number: if complete: - kind = packets.FrontToBackPacket.Kind.COMPLETION + kind = interfaces.FrontToBackPacket.Kind.COMPLETION else: - kind = packets.FrontToBackPacket.Kind.CONTINUATION - return packets.FrontToBackPacket( + kind = interfaces.FrontToBackPacket.Kind.CONTINUATION + return interfaces.FrontToBackPacket( operation_id, sequence_number, kind, self._name, self._subscription_kind, self._trace_id, payload, self._timeout) else: if complete: - kind = packets.FrontToBackPacket.Kind.ENTIRE + kind = interfaces.FrontToBackPacket.Kind.ENTIRE else: - kind = packets.FrontToBackPacket.Kind.COMMENCEMENT - return packets.FrontToBackPacket( + kind = interfaces.FrontToBackPacket.Kind.COMMENCEMENT + return interfaces.FrontToBackPacket( operation_id, 0, kind, self._name, self._subscription_kind, self._trace_id, payload, self._timeout) @@ -162,7 +161,7 @@ class _FrontPacketizer(_Packetizer): return None else: kind = _ABORTION_OUTCOME_TO_FRONT_TO_BACK_PACKET_KIND[outcome] - return packets.FrontToBackPacket( + return interfaces.FrontToBackPacket( operation_id, sequence_number, kind, None, None, None, None, None) @@ -172,10 +171,10 @@ class _BackPacketizer(_Packetizer): def packetize(self, operation_id, sequence_number, payload, complete): """See _Packetizer.packetize for specification.""" if complete: - kind = packets.BackToFrontPacket.Kind.COMPLETION + kind = interfaces.BackToFrontPacket.Kind.COMPLETION else: - kind = packets.BackToFrontPacket.Kind.CONTINUATION - return packets.BackToFrontPacket( + kind = interfaces.BackToFrontPacket.Kind.CONTINUATION + return interfaces.BackToFrontPacket( operation_id, sequence_number, kind, payload) def packetize_abortion(self, operation_id, sequence_number, outcome): @@ -184,7 +183,7 @@ class _BackPacketizer(_Packetizer): return None else: kind = _ABORTION_OUTCOME_TO_BACK_TO_FRONT_PACKET_KIND[outcome] - return packets.BackToFrontPacket( + return interfaces.BackToFrontPacket( operation_id, sequence_number, kind, None) diff --git a/src/python/src/grpc/framework/base/packets/implementations.py b/src/python/src/grpc/framework/base/implementations.py similarity index 77% rename from src/python/src/grpc/framework/base/packets/implementations.py rename to src/python/src/grpc/framework/base/implementations.py index 28688bcc0f..70fb9942b2 100644 --- a/src/python/src/grpc/framework/base/packets/implementations.py +++ b/src/python/src/grpc/framework/base/implementations.py @@ -30,48 +30,48 @@ """Entry points into the packet-exchange-based implementation the base layer.""" # interfaces is referenced from specification in this module. -from grpc.framework.base.packets import _ends -from grpc.framework.base.packets import interfaces # pylint: disable=unused-import +from grpc.framework.base import _ends +from grpc.framework.base import interfaces # pylint: disable=unused-import -def front(work_pool, transmission_pool, utility_pool): - """Factory function for creating interfaces.Fronts. +def front_link(work_pool, transmission_pool, utility_pool): + """Factory function for creating interfaces.FrontLinks. Args: - work_pool: A thread pool to be used for doing work within the created Front - object. - transmission_pool: A thread pool to be used within the created Front object - for transmitting values to some Back object. - utility_pool: A thread pool to be used within the created Front object for - utility tasks. + work_pool: A thread pool to be used for doing work within the created + FrontLink object. + transmission_pool: A thread pool to be used within the created FrontLink + object for transmitting values to a joined RearLink object. + utility_pool: A thread pool to be used within the created FrontLink object + for utility tasks. Returns: - An interfaces.Front. + An interfaces.FrontLink. """ - return _ends.Front(work_pool, transmission_pool, utility_pool) + return _ends.FrontLink(work_pool, transmission_pool, utility_pool) -def back( +def back_link( servicer, work_pool, transmission_pool, utility_pool, default_timeout, maximum_timeout): - """Factory function for creating interfaces.Backs. + """Factory function for creating interfaces.BackLinks. Args: servicer: An interfaces.Servicer for servicing operations. - work_pool: A thread pool to be used for doing work within the created Back - object. - transmission_pool: A thread pool to be used within the created Back object - for transmitting values to some Front object. - utility_pool: A thread pool to be used within the created Back object for - utility tasks. + work_pool: A thread pool to be used for doing work within the created + BackLink object. + transmission_pool: A thread pool to be used within the created BackLink + object for transmitting values to a joined ForeLink object. + utility_pool: A thread pool to be used within the created BackLink object + for utility tasks. default_timeout: A length of time in seconds to be used as the default time alloted for a single operation. maximum_timeout: A length of time in seconds to be used as the maximum time alloted for a single operation. Returns: - An interfaces.Back. + An interfaces.BackLink. """ - return _ends.Back( + return _ends.BackLink( servicer, work_pool, transmission_pool, utility_pool, default_timeout, maximum_timeout) diff --git a/src/python/src/grpc/framework/base/packets/implementations_test.py b/src/python/src/grpc/framework/base/implementations_test.py similarity index 94% rename from src/python/src/grpc/framework/base/packets/implementations_test.py rename to src/python/src/grpc/framework/base/implementations_test.py index e5855700c7..11e49caf75 100644 --- a/src/python/src/grpc/framework/base/packets/implementations_test.py +++ b/src/python/src/grpc/framework/base/implementations_test.py @@ -27,13 +27,13 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""Tests for _framework.base.packets.implementations.""" +"""Tests for grpc.framework.base.implementations.""" import unittest +from grpc.framework.base import implementations from grpc.framework.base import interfaces_test_case from grpc.framework.base import util -from grpc.framework.base.packets import implementations from grpc.framework.foundation import logging_pool POOL_MAX_WORKERS = 100 @@ -54,10 +54,10 @@ class ImplementationsTest( 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( + self.front = implementations.front_link( self.front_work_pool, self.front_transmission_pool, self.front_utility_pool) - self.back = implementations.back( + 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) diff --git a/src/python/src/grpc/framework/base/packets/in_memory.py b/src/python/src/grpc/framework/base/in_memory.py similarity index 97% rename from src/python/src/grpc/framework/base/packets/in_memory.py rename to src/python/src/grpc/framework/base/in_memory.py index 453fd3b38a..9ed62f8e0a 100644 --- a/src/python/src/grpc/framework/base/packets/in_memory.py +++ b/src/python/src/grpc/framework/base/in_memory.py @@ -31,8 +31,8 @@ import threading -from grpc.framework.base.packets import _constants -from grpc.framework.base.packets import interfaces +from grpc.framework.base import _constants +from grpc.framework.base import interfaces from grpc.framework.foundation import callable_util diff --git a/src/python/src/grpc/framework/base/interfaces.py b/src/python/src/grpc/framework/base/interfaces.py index ed43b253fe..7be13b3f45 100644 --- a/src/python/src/grpc/framework/base/interfaces.py +++ b/src/python/src/grpc/framework/base/interfaces.py @@ -30,6 +30,7 @@ """Interfaces defined and used by the base layer of RPC Framework.""" import abc +import collections import enum # stream is referenced from specification in this module. @@ -230,3 +231,133 @@ class Front(End): class Back(End): """Serverish objects that perform the work of operations.""" __metaclass__ = abc.ABCMeta + + +class FrontToBackPacket( + collections.namedtuple( + 'FrontToBackPacket', + ['operation_id', 'sequence_number', 'kind', 'name', 'subscription', + 'trace_id', 'payload', 'timeout'])): + """A sum type for all values sent from a front to a back. + + Attributes: + operation_id: A unique-with-respect-to-equality hashable object identifying + a particular operation. + sequence_number: A zero-indexed integer sequence number identifying the + packet's place among all the packets sent from front to back for this + particular operation. Must be zero if kind is Kind.COMMENCEMENT or + Kind.ENTIRE. Must be positive for any other kind. + kind: A Kind value describing the overall kind of ticket. + name: The name of an operation. Must be present if kind is Kind.COMMENCEMENT + or Kind.ENTIRE. Must be None for any other kind. + subscription: An ServicedSubscription.Kind value describing the interest + the front has in packets sent from the back. Must be present if + kind is Kind.COMMENCEMENT or Kind.ENTIRE. Must be None for any other kind. + trace_id: A uuid.UUID identifying a set of related operations to which this + operation belongs. May be None. + payload: A customer payload object. Must be present if kind is + Kind.CONTINUATION. Must be None if kind is Kind.CANCELLATION. May be None + for any other kind. + timeout: An optional length of time (measured from the beginning of the + operation) to allow for the entire operation. If None, a default value on + the back will be used. If present and excessively large, the back may + limit the operation to a smaller duration of its choice. May be present + for any ticket kind; setting a value on a later ticket allows fronts + to request time extensions (or even time reductions!) on in-progress + operations. + """ + + @enum.unique + class Kind(enum.Enum): + """Identifies the overall kind of a FrontToBackPacket.""" + + COMMENCEMENT = 'commencement' + CONTINUATION = 'continuation' + COMPLETION = 'completion' + ENTIRE = 'entire' + CANCELLATION = 'cancellation' + EXPIRATION = 'expiration' + SERVICER_FAILURE = 'servicer failure' + SERVICED_FAILURE = 'serviced failure' + RECEPTION_FAILURE = 'reception failure' + TRANSMISSION_FAILURE = 'transmission failure' + + +class BackToFrontPacket( + collections.namedtuple( + 'BackToFrontPacket', + ['operation_id', 'sequence_number', 'kind', 'payload'])): + """A sum type for all values sent from a back to a front. + + Attributes: + operation_id: A unique-with-respect-to-equality hashable object identifying + a particular operation. + sequence_number: A zero-indexed integer sequence number identifying the + packet's place among all the packets sent from back to front for this + particular operation. + kind: A Kind value describing the overall kind of ticket. + payload: A customer payload object. Must be present if kind is + Kind.CONTINUATION. May be None if kind is Kind.COMPLETION. Must be None + otherwise. + """ + + @enum.unique + class Kind(enum.Enum): + """Identifies the overall kind of a BackToFrontPacket.""" + + CONTINUATION = 'continuation' + COMPLETION = 'completion' + CANCELLATION = 'cancellation' + EXPIRATION = 'expiration' + SERVICER_FAILURE = 'servicer failure' + SERVICED_FAILURE = 'serviced failure' + RECEPTION_FAILURE = 'reception failure' + TRANSMISSION_FAILURE = 'transmission failure' + + +class ForeLink(object): + """Accepts back-to-front tickets and emits front-to-back tickets.""" + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def accept_back_to_front_ticket(self, ticket): + """Accept a BackToFrontPacket. + + Args: + ticket: Any BackToFrontPacket. + """ + raise NotImplementedError() + + @abc.abstractmethod + def join_rear_link(self, rear_link): + """Mates this object with a peer with which it will exchange tickets.""" + raise NotImplementedError() + + +class RearLink(object): + """Accepts front-to-back tickets and emits back-to-front tickets.""" + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def accept_front_to_back_ticket(self, ticket): + """Accepts a FrontToBackPacket. + + Args: + ticket: Any FrontToBackPacket. + """ + raise NotImplementedError() + + @abc.abstractmethod + def join_fore_link(self, fore_link): + """Mates this object with a peer with which it will exchange tickets.""" + raise NotImplementedError() + + +class FrontLink(Front, ForeLink): + """Clientish objects that operate by sending and receiving tickets.""" + __metaclass__ = abc.ABCMeta + + +class BackLink(Back, RearLink): + """Serverish objects that operate by sending and receiving tickets.""" + __metaclass__ = abc.ABCMeta diff --git a/src/python/src/grpc/framework/base/packets/null.py b/src/python/src/grpc/framework/base/null.py similarity index 97% rename from src/python/src/grpc/framework/base/packets/null.py rename to src/python/src/grpc/framework/base/null.py index 5a2121243b..1e30d4557b 100644 --- a/src/python/src/grpc/framework/base/packets/null.py +++ b/src/python/src/grpc/framework/base/null.py @@ -29,7 +29,7 @@ """Null links that ignore tickets passed to them.""" -from grpc.framework.base.packets import interfaces +from grpc.framework.base import interfaces class _NullForeLink(interfaces.ForeLink): diff --git a/src/python/src/grpc/framework/base/packets/__init__.py b/src/python/src/grpc/framework/base/packets/__init__.py deleted file mode 100644 index 7086519106..0000000000 --- a/src/python/src/grpc/framework/base/packets/__init__.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2015, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - diff --git a/src/python/src/grpc/framework/base/packets/interfaces.py b/src/python/src/grpc/framework/base/packets/interfaces.py deleted file mode 100644 index 7c48956ba5..0000000000 --- a/src/python/src/grpc/framework/base/packets/interfaces.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2015, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -"""Interfaces defined and used by the base layer of RPC Framework.""" - -import abc - -# packets is referenced from specifications in this module. -from grpc.framework.base import interfaces -from grpc.framework.base.packets import packets # pylint: disable=unused-import - - -class ForeLink(object): - """Accepts back-to-front tickets and emits front-to-back tickets.""" - __metaclass__ = abc.ABCMeta - - @abc.abstractmethod - def accept_back_to_front_ticket(self, ticket): - """Accept a packets.BackToFrontPacket. - - Args: - ticket: Any packets.BackToFrontPacket. - """ - raise NotImplementedError() - - @abc.abstractmethod - def join_rear_link(self, rear_link): - """Mates this object with a peer with which it will exchange tickets.""" - raise NotImplementedError() - - -class RearLink(object): - """Accepts front-to-back tickets and emits back-to-front tickets.""" - __metaclass__ = abc.ABCMeta - - @abc.abstractmethod - def accept_front_to_back_ticket(self, ticket): - """Accepts a packets.FrontToBackPacket. - - Args: - ticket: Any packets.FrontToBackPacket. - """ - raise NotImplementedError() - - @abc.abstractmethod - def join_fore_link(self, fore_link): - """Mates this object with a peer with which it will exchange tickets.""" - raise NotImplementedError() - - -class Front(ForeLink, interfaces.Front): - """Clientish objects that operate by sending and receiving tickets.""" - __metaclass__ = abc.ABCMeta - - -class Back(RearLink, interfaces.Back): - """Serverish objects that operate by sending and receiving tickets.""" - __metaclass__ = abc.ABCMeta diff --git a/src/python/src/grpc/framework/base/packets/packets.py b/src/python/src/grpc/framework/base/packets/packets.py deleted file mode 100644 index 1b140481f0..0000000000 --- a/src/python/src/grpc/framework/base/packets/packets.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright 2015, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -"""Packets used between fronts and backs.""" - -import collections -import enum - -# interfaces is referenced from specifications in this module. -from grpc.framework.base import interfaces # pylint: disable=unused-import - - -class FrontToBackPacket( - collections.namedtuple( - 'FrontToBackPacket', - ['operation_id', 'sequence_number', 'kind', 'name', 'subscription', - 'trace_id', 'payload', 'timeout'])): - """A sum type for all values sent from a front to a back. - - Attributes: - operation_id: A unique-with-respect-to-equality hashable object identifying - a particular operation. - sequence_number: A zero-indexed integer sequence number identifying the - packet's place among all the packets sent from front to back for this - particular operation. Must be zero if kind is Kind.COMMENCEMENT or - Kind.ENTIRE. Must be positive for any other kind. - kind: A Kind value describing the overall kind of ticket. - name: The name of an operation. Must be present if kind is Kind.COMMENCEMENT - or Kind.ENTIRE. Must be None for any other kind. - subscription: An interfaces.ServicedSubscription.Kind value describing the - interest the front has in packets sent from the back. Must be present if - kind is Kind.COMMENCEMENT or Kind.ENTIRE. Must be None for any other kind. - trace_id: A uuid.UUID identifying a set of related operations to which this - operation belongs. May be None. - payload: A customer payload object. Must be present if kind is - Kind.CONTINUATION. Must be None if kind is Kind.CANCELLATION. May be None - for any other kind. - timeout: An optional length of time (measured from the beginning of the - operation) to allow for the entire operation. If None, a default value on - the back will be used. If present and excessively large, the back may - limit the operation to a smaller duration of its choice. May be present - for any ticket kind; setting a value on a later ticket allows fronts - to request time extensions (or even time reductions!) on in-progress - operations. - """ - - @enum.unique - class Kind(enum.Enum): - """Identifies the overall kind of a FrontToBackPacket.""" - - COMMENCEMENT = 'commencement' - CONTINUATION = 'continuation' - COMPLETION = 'completion' - ENTIRE = 'entire' - CANCELLATION = 'cancellation' - EXPIRATION = 'expiration' - SERVICER_FAILURE = 'servicer failure' - SERVICED_FAILURE = 'serviced failure' - RECEPTION_FAILURE = 'reception failure' - TRANSMISSION_FAILURE = 'transmission failure' - - -class BackToFrontPacket( - collections.namedtuple( - 'BackToFrontPacket', - ['operation_id', 'sequence_number', 'kind', 'payload'])): - """A sum type for all values sent from a back to a front. - - Attributes: - operation_id: A unique-with-respect-to-equality hashable object identifying - a particular operation. - sequence_number: A zero-indexed integer sequence number identifying the - packet's place among all the packets sent from back to front for this - particular operation. - kind: A Kind value describing the overall kind of ticket. - payload: A customer payload object. Must be present if kind is - Kind.CONTINUATION. May be None if kind is Kind.COMPLETION. Must be None - otherwise. - """ - - @enum.unique - class Kind(enum.Enum): - """Identifies the overall kind of a BackToFrontPacket.""" - - CONTINUATION = 'continuation' - COMPLETION = 'completion' - CANCELLATION = 'cancellation' - EXPIRATION = 'expiration' - SERVICER_FAILURE = 'servicer failure' - SERVICED_FAILURE = 'serviced failure' - RECEPTION_FAILURE = 'reception failure' - TRANSMISSION_FAILURE = 'transmission failure' diff --git a/src/python/src/grpc/framework/face/demonstration.py b/src/python/src/grpc/framework/face/demonstration.py index d922f6e5ef..eabeac4569 100644 --- a/src/python/src/grpc/framework/face/demonstration.py +++ b/src/python/src/grpc/framework/face/demonstration.py @@ -30,7 +30,7 @@ """Demonstration-suitable implementation of the face layer of RPC Framework.""" from grpc.framework.base import util as _base_util -from grpc.framework.base.packets import implementations as _tickets_implementations +from grpc.framework.base import implementations as _base_implementations from grpc.framework.face import implementations from grpc.framework.foundation import logging_pool @@ -105,9 +105,9 @@ def server_and_stub( event_stream_in_stream_out_methods=event_stream_in_stream_out_methods, multi_method=multi_method) - front = _tickets_implementations.front( + front = _base_implementations.front_link( front_work_pool, front_transmission_pool, front_utility_pool) - back = _tickets_implementations.back( + back = _base_implementations.back_link( servicer, back_work_pool, back_transmission_pool, back_utility_pool, default_timeout, _MAXIMUM_TIMEOUT) front.join_rear_link(back) diff --git a/src/python/src/grpc/framework/face/testing/base_util.py b/src/python/src/grpc/framework/face/testing/base_util.py index 7872a6b9e9..151d0ef793 100644 --- a/src/python/src/grpc/framework/face/testing/base_util.py +++ b/src/python/src/grpc/framework/face/testing/base_util.py @@ -33,9 +33,9 @@ import abc # interfaces is referenced from specification in this module. from grpc.framework.base import util as _base_util -from grpc.framework.base.packets import implementations -from grpc.framework.base.packets import in_memory -from grpc.framework.base.packets import interfaces # pylint: disable=unused-import +from grpc.framework.base import implementations +from grpc.framework.base import in_memory +from grpc.framework.base import interfaces # pylint: disable=unused-import from grpc.framework.foundation import logging_pool _POOL_SIZE_LIMIT = 20 @@ -89,9 +89,9 @@ def linked_pair(servicer, default_timeout): back_work_pool, back_transmission_pool, back_utility_pool) link = in_memory.Link(link_pool) - front = implementations.front( + front = implementations.front_link( front_work_pool, front_transmission_pool, front_utility_pool) - back = implementations.back( + back = implementations.back_link( servicer, back_work_pool, back_transmission_pool, back_utility_pool, default_timeout, _MAXIMUM_TIMEOUT) front.join_rear_link(link) diff --git a/src/python/src/setup.py b/src/python/src/setup.py index 7d93aa7ded..63731212c7 100644 --- a/src/python/src/setup.py +++ b/src/python/src/setup.py @@ -65,7 +65,6 @@ _PACKAGES = ( 'grpc.early_adopter', 'grpc.framework', 'grpc.framework.base', - 'grpc.framework.base.packets', 'grpc.framework.common', 'grpc.framework.face', 'grpc.framework.face.testing', diff --git a/tools/dockerfile/grpc_python/Dockerfile b/tools/dockerfile/grpc_python/Dockerfile index fd07e9cc6a..62ef785a31 100644 --- a/tools/dockerfile/grpc_python/Dockerfile +++ b/tools/dockerfile/grpc_python/Dockerfile @@ -54,7 +54,7 @@ RUN cd /var/local/git/grpc \ && python2.7 -B -m grpc._adapter._lonely_rear_link_test \ && python2.7 -B -m grpc._adapter._low_test \ && python2.7 -B -m grpc.early_adopter.implementations_test \ - && python2.7 -B -m grpc.framework.base.packets.implementations_test \ + && python2.7 -B -m grpc.framework.base.implementations_test \ && python2.7 -B -m grpc.framework.face.blocking_invocation_inline_service_test \ && python2.7 -B -m grpc.framework.face.event_invocation_synchronous_event_service_test \ && python2.7 -B -m grpc.framework.face.future_invocation_asynchronous_event_service_test \ diff --git a/tools/run_tests/python_tests.json b/tools/run_tests/python_tests.json index ef483d9799..dff053784d 100755 --- a/tools/run_tests/python_tests.json +++ b/tools/run_tests/python_tests.json @@ -27,7 +27,7 @@ "module": "grpc.early_adopter.implementations_test" }, { - "module": "grpc.framework.base.packets.implementations_test" + "module": "grpc.framework.base.implementations_test" }, { "module": "grpc.framework.face.blocking_invocation_inline_service_test" -- GitLab