Exemple #1
0
 def rear_action(front_to_back_ticket, fore_link):
     if front_to_back_ticket.kind in (tickets.Kind.COMPLETION,
                                      tickets.Kind.ENTIRE):
         back_to_front_ticket = tickets.BackToFrontPacket(
             front_to_back_ticket.operation_id, 0,
             tickets.Kind.COMPLETION, None)
         fore_link.accept_back_to_front_ticket(back_to_front_ticket)
Exemple #2
0
 def packetize_abortion(self, operation_id, sequence_number, kind):
     """See _Packetizer.packetize_abortion for specification."""
     if kind in _BACK_TO_FRONT_NO_TRANSMISSION_KINDS:
         return None
     else:
         return packets.BackToFrontPacket(operation_id, sequence_number,
                                          kind, None)
Exemple #3
0
 def _on_complete_event(self, operation_id, event, rpc_state):
     if not event.complete_accepted:
         logging.error('RPC complete not accepted! Event: %s', (event, ))
         rpc_state.active = False
         ticket = tickets.BackToFrontPacket(
             operation_id, rpc_state.common.sequence_number,
             tickets.Kind.TRANSMISSION_FAILURE, None)
         rpc_state.common.sequence_number += 1
         self._fore_link.accept_back_to_front_ticket(ticket)
Exemple #4
0
    def _on_read_event(self, operation_id, event, rpc_state):
        if event.bytes is not None:
            rpc_state.call.read(operation_id)
            rpc_state.outstanding.add(_low.Event.Kind.READ_ACCEPTED)

            ticket = tickets.BackToFrontPacket(
                operation_id, rpc_state.common.sequence_number,
                tickets.Kind.CONTINUATION,
                rpc_state.common.deserializer(event.bytes))
            rpc_state.common.sequence_number += 1
            self._fore_link.accept_back_to_front_ticket(ticket)
Exemple #5
0
 def rear_action(front_to_back_ticket, fore_link):
   if front_to_back_ticket.payload is None:
     payload = None
   else:
     payload = test_back_to_front_datum
   terminal = front_to_back_ticket.kind in (
       tickets.Kind.COMPLETION, tickets.Kind.ENTIRE)
   if payload is not None or terminal:
     back_to_front_ticket = tickets.BackToFrontPacket(
         front_to_back_ticket.operation_id, rear_sequence_number[0],
         tickets.Kind.COMPLETION if terminal else tickets.Kind.CONTINUATION,
         payload)
     rear_sequence_number[0] += 1
     fore_link.accept_back_to_front_ticket(back_to_front_ticket)
Exemple #6
0
 def rear_action(front_to_back_ticket, fore_link):
   with rear_lock:
     if front_to_back_ticket.payload is not None:
       response = scenario.response_for_request(front_to_back_ticket.payload)
     else:
       response = None
   terminal = front_to_back_ticket.kind in (
       tickets.Kind.COMPLETION, tickets.Kind.ENTIRE)
   if response is not None or terminal:
     back_to_front_ticket = tickets.BackToFrontPacket(
         front_to_back_ticket.operation_id, rear_sequence_number[0],
         tickets.Kind.COMPLETION if terminal else tickets.Kind.CONTINUATION,
         response)
     rear_sequence_number[0] += 1
     fore_link.accept_back_to_front_ticket(back_to_front_ticket)
Exemple #7
0
 def _on_finish_event(self, operation_id, event, rpc_state):
     """Handle termination of an RPC."""
     # TODO(nathaniel): Cover all statuses.
     if event.status.code is _low.Code.OK:
         category = tickets.Kind.COMPLETION
     elif event.status.code is _low.Code.CANCELLED:
         # TODO(issue 752): Use a CANCELLATION ticket kind here.
         category = tickets.Kind.SERVICER_FAILURE
     elif event.status.code is _low.Code.EXPIRED:
         category = tickets.Kind.EXPIRATION
     else:
         category = tickets.Kind.TRANSMISSION_FAILURE
     ticket = tickets.BackToFrontPacket(operation_id,
                                        rpc_state.common.sequence_number,
                                        category, None)
     rpc_state.common.sequence_number += 1
     self._fore_link.accept_back_to_front_ticket(ticket)
Exemple #8
0
 def _on_write_event(self, operation_id, event, rpc_state):
     if event.write_accepted:
         if rpc_state.common.write.pending:
             rpc_state.call.write(rpc_state.common.write.pending.pop(0),
                                  operation_id)
             rpc_state.outstanding.add(_low.Event.Kind.WRITE_ACCEPTED)
         elif rpc_state.common.write.high is _common.HighWrite.CLOSED:
             rpc_state.call.complete(operation_id)
             rpc_state.outstanding.add(_low.Event.Kind.COMPLETE_ACCEPTED)
             rpc_state.common.write.low = _LowWrite.CLOSED
         else:
             rpc_state.common.write.low = _LowWrite.OPEN
     else:
         logging.error('RPC write not accepted! Event: %s', (event, ))
         rpc_state.active = False
         ticket = tickets.BackToFrontPacket(
             operation_id, rpc_state.common.sequence_number,
             tickets.Kind.TRANSMISSION_FAILURE, None)
         rpc_state.common.sequence_number += 1
         self._fore_link.accept_back_to_front_ticket(ticket)
Exemple #9
0
 def packetize(self, operation_id, sequence_number, payload, complete):
     """See _Packetizer.packetize for specification."""
     return packets.BackToFrontPacket(
         operation_id, sequence_number,
         packets.Kind.COMPLETION if complete else packets.Kind.CONTINUATION,
         payload)