def _abort(self, outcome_kind): with self._lock: if self._termination_manager.outcome is None: outcome = _utilities.Outcome(outcome_kind, None, None) self._termination_manager.abort(outcome) self._transmission_manager.abort(outcome) self._expiration_manager.terminate()
def _abort_and_notify(self, outcome_kind, code, details): self._abort_internal_only() if self._termination_manager.outcome is None: outcome = _utilities.Outcome(outcome_kind, code, details) self._termination_manager.abort(outcome) self._transmission_manager.abort(outcome) self._expiration_manager.terminate()
def advance(self, initial_metadata=None, payload=None, completion=None, allowance=None): initial_metadata_present = initial_metadata is not None payload_present = payload is not None completion_present = completion is not None allowance_present = allowance is not None with self._lock: if self._termination_manager.outcome is None: if (initial_metadata_present and (self._initial_metadata_seen or self._payload_seen or self._completion_seen) or payload_present and self._completion_seen or completion_present and self._completion_seen or allowance_present and allowance <= 0): outcome = _utilities.Outcome( base.Outcome.Kind.LOCAL_FAILURE, None, None) self._termination_manager.abort(outcome) self._transmission_manager.abort(outcome) self._expiration_manager.terminate() else: self._initial_metadata_seen |= initial_metadata_present self._payload_seen |= payload_present self._completion_seen |= completion_present if completion_present: self._termination_manager.emission_complete() self._ingestion_manager.local_emissions_done() self._transmission_manager.advance(initial_metadata, payload, completion, allowance) if allowance_present: self._ingestion_manager.add_local_allowance(allowance)
def expire(): with self._lock: if self._future is not None and index == self._index: self._future = None self._termination_manager.expire() self._transmission_manager.abort( _utilities.Outcome(base.Outcome.Kind.EXPIRED, None, None))
def _perhaps_complete(self): if self._predicate( self._emission_complete, self._transmission_complete, self._reception_complete, self._ingestion_complete): self._terminate_and_notify( _utilities.Outcome( base.Outcome.Kind.COMPLETED, self._code, self._details)) return True else: return False
def receive_ticket(self, ticket): """See _interfaces.ReceptionManager.receive_ticket for specification.""" if self._aborted: return elif self._sequence_failure(ticket): self._abort(_RECEPTION_FAILURE_OUTCOME) elif ticket.termination not in (None, links.Ticket.Termination.COMPLETION): outcome_kind = _REMOTE_TICKET_TERMINATION_TO_LOCAL_OUTCOME_KIND[ ticket.termination] self._abort( _utilities.Outcome(outcome_kind, ticket.code, ticket.message)) elif ticket.sequence_number == self._lowest_unseen_sequence_number: self._process(ticket) else: self._out_of_sequence_tickets[ticket.sequence_number] = ticket
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """State and behavior for passing protocol objects in an operation.""" import collections import enum from grpc.framework.core import _constants from grpc.framework.core import _interfaces from grpc.framework.core import _utilities from grpc.framework.foundation import callable_util from grpc.framework.interfaces.base import base _EXCEPTION_LOG_MESSAGE = 'Exception delivering protocol object!' _LOCAL_FAILURE_OUTCOME = _utilities.Outcome(base.Outcome.Kind.LOCAL_FAILURE, None, None) class _Awaited(collections.namedtuple('_Awaited', ( 'kind', 'value', ))): @enum.unique class Kind(enum.Enum): NOT_YET_ARRIVED = 'not yet arrived' ARRIVED = 'arrived' _NOT_YET_ARRIVED = _Awaited(_Awaited.Kind.NOT_YET_ARRIVED, None) _ARRIVED_AND_NONE = _Awaited(_Awaited.Kind.ARRIVED, None)
def expire(self): """See _interfaces.TerminationManager.expire for specification.""" self._terminate_internal_only( _utilities.Outcome(base.Outcome.Kind.EXPIRED, None, None))
from grpc.framework.interfaces.base import utilities from grpc.framework.interfaces.links import links _REMOTE_TICKET_TERMINATION_TO_LOCAL_OUTCOME_KIND = { links.Ticket.Termination.CANCELLATION: base.Outcome.Kind.CANCELLED, links.Ticket.Termination.EXPIRATION: base.Outcome.Kind.EXPIRED, links.Ticket.Termination.SHUTDOWN: base.Outcome.Kind.REMOTE_SHUTDOWN, links.Ticket.Termination.RECEPTION_FAILURE: base.Outcome.Kind.RECEPTION_FAILURE, links.Ticket.Termination.TRANSMISSION_FAILURE: base.Outcome.Kind.TRANSMISSION_FAILURE, links.Ticket.Termination.LOCAL_FAILURE: base.Outcome.Kind.REMOTE_FAILURE, links.Ticket.Termination.REMOTE_FAILURE: base.Outcome.Kind.LOCAL_FAILURE, } _RECEPTION_FAILURE_OUTCOME = _utilities.Outcome( base.Outcome.Kind.RECEPTION_FAILURE, None, None) def _carrying_protocol_context(ticket): return ticket.protocol is not None and ticket.protocol.kind in ( links.Protocol.Kind.INVOCATION_CONTEXT, links.Protocol.Kind.SERVICER_CONTEXT, ) class ReceptionManager(_interfaces.ReceptionManager): """A ReceptionManager based around a _Receiver passed to it.""" def __init__(self, termination_manager, transmission_manager, expiration_manager, protocol_manager, ingestion_manager): """Constructor.
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """State and behavior for ticket transmission during an operation.""" import collections import enum from grpc.framework.core import _constants from grpc.framework.core import _interfaces from grpc.framework.core import _utilities from grpc.framework.foundation import callable_util from grpc.framework.interfaces.base import base from grpc.framework.interfaces.links import links _TRANSMISSION_EXCEPTION_LOG_MESSAGE = 'Exception during transmission!' _TRANSMISSION_FAILURE_OUTCOME = _utilities.Outcome( base.Outcome.Kind.TRANSMISSION_FAILURE, None, None) def _explode_completion(completion): if completion is None: return None, None, None, None else: return (completion.terminal_metadata, completion.code, completion.message, links.Ticket.Termination.COMPLETION) class _Abort( collections.namedtuple('_Abort', ( 'kind', 'termination', 'code',