Esempio n. 1
0
def _abort(state, call, code, details):
  if state.client is not _CANCELLED:
    effective_code = _abortion_code(state, code)
    effective_details = details if state.details is None else state.details
    if state.initial_metadata_allowed:
      operations = (
          cygrpc.operation_send_initial_metadata(
              _EMPTY_METADATA, _EMPTY_FLAGS),
          cygrpc.operation_send_status_from_server(
              _common.metadata(state.trailing_metadata), effective_code,
              effective_details, _EMPTY_FLAGS),
      )
      token = _SEND_INITIAL_METADATA_AND_SEND_STATUS_FROM_SERVER_TOKEN
    else:
      operations = (
          cygrpc.operation_send_status_from_server(
              _common.metadata(state.trailing_metadata), effective_code,
              effective_details, _EMPTY_FLAGS),
      )
      token = _SEND_STATUS_FROM_SERVER_TOKEN
    call.start_batch(
        cygrpc.Operations(operations),
        _send_status_from_server(state, token))
    state.statused = True
    state.due.add(token)
Esempio n. 2
0
 def _blocking(self, request_iterator, timeout, metadata, credentials):
   deadline, deadline_timespec = _deadline(timeout)
   state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None)
   completion_queue = cygrpc.CompletionQueue()
   call = self._channel.create_call(
       None, 0, completion_queue, self._method, None, deadline_timespec)
   if credentials is not None:
     call.set_credentials(credentials._credentials)
   with state.condition:
     call.start_batch(
         cygrpc.Operations(
             (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)),
         None)
     operations = (
         cygrpc.operation_send_initial_metadata(
             _common.metadata(metadata), _EMPTY_FLAGS),
         cygrpc.operation_receive_message(_EMPTY_FLAGS),
         cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
     )
     call.start_batch(cygrpc.Operations(operations), None)
     _consume_request_iterator(
         request_iterator, state, call, self._request_serializer)
   while True:
     event = completion_queue.poll()
     with state.condition:
       _handle_event(event, state, self._response_deserializer)
       state.condition.notify_all()
       if not state.due:
         break
   return state, deadline
Esempio n. 3
0
 def __call__(self, request, timeout=None, metadata=None, credentials=None):
   deadline, deadline_timespec, serialized_request, rendezvous = (
       _start_unary_request(request, timeout, self._request_serializer))
   if serialized_request is None:
     raise rendezvous
   else:
     state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None)
     call = self._create_managed_call(
         None, 0, self._method, None, deadline_timespec)
     if credentials is not None:
       call.set_credentials(credentials._credentials)
     event_handler = _event_handler(state, call, self._response_deserializer)
     with state.condition:
       call.start_batch(
           cygrpc.Operations(
               (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)),
           event_handler)
       operations = (
           cygrpc.operation_send_initial_metadata(
               _common.metadata(metadata), _EMPTY_FLAGS),
           cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS),
           cygrpc.operation_send_close_from_client(_EMPTY_FLAGS),
           cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
       )
       call.start_batch(cygrpc.Operations(operations), event_handler)
     return _Rendezvous(state, call, self._response_deserializer, deadline)
Esempio n. 4
0
 def __call__(self,
              request_iterator,
              timeout=None,
              metadata=None,
              credentials=None):
     deadline, deadline_timespec = _deadline(timeout)
     state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None)
     call = self._create_managed_call(None, 0, self._method, None,
                                      deadline_timespec)
     if credentials is not None:
         call.set_credentials(credentials._credentials)
     event_handler = _event_handler(state, call,
                                    self._response_deserializer)
     with state.condition:
         call.start_batch(
             cygrpc.Operations(
                 (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),
                  )), event_handler)
         operations = (
             cygrpc.operation_send_initial_metadata(
                 _common.metadata(metadata), _EMPTY_FLAGS),
             cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
         )
         call.start_batch(cygrpc.Operations(operations), event_handler)
         _consume_request_iterator(request_iterator, state, call,
                                   self._request_serializer)
     return _Rendezvous(state, call, self._response_deserializer, deadline)
Esempio n. 5
0
def _abort(state, call, code, details):
    if state.client is not _CANCELLED:
        if state.initial_metadata_allowed:
            operations = (
                cygrpc.operation_send_initial_metadata(_EMPTY_METADATA,
                                                       _EMPTY_FLAGS),
                cygrpc.operation_send_status_from_server(
                    _common.metadata(state.trailing_metadata), code, details,
                    _EMPTY_FLAGS),
            )
            token = _SEND_INITIAL_METADATA_AND_SEND_STATUS_FROM_SERVER_TOKEN
        else:
            operations = (cygrpc.operation_send_status_from_server(
                _common.metadata(state.trailing_metadata), code, details,
                _EMPTY_FLAGS), )
            token = _SEND_STATUS_FROM_SERVER_TOKEN
        call.start_batch(cygrpc.Operations(operations),
                         _send_status_from_server(state, token))
        state.statused = True
        state.due.add(token)
Esempio n. 6
0
 def send_initial_metadata(self, initial_metadata):
     with self._state.condition:
         if self._state.client is _CANCELLED:
             _raise_rpc_error(self._state)
         else:
             if self._state.initial_metadata_allowed:
                 operation = cygrpc.operation_send_initial_metadata(
                     _common.metadata(initial_metadata), _EMPTY_FLAGS)
                 self._rpc_event.operation_call.start_batch(
                     cygrpc.Operations((operation, )),
                     _send_initial_metadata(self._state))
                 self._state.initial_metadata_allowed = False
                 self._state.due.add(_SEND_INITIAL_METADATA_TOKEN)
             else:
                 raise ValueError('Initial metadata no longer allowed!')
Esempio n. 7
0
 def send_initial_metadata(self, initial_metadata):
   with self._state.condition:
     if self._state.client is _CANCELLED:
       _raise_rpc_error(self._state)
     else:
       if self._state.initial_metadata_allowed:
         operation = cygrpc.operation_send_initial_metadata(
             _common.metadata(initial_metadata), _EMPTY_FLAGS)
         self._rpc_event.operation_call.start_batch(
             cygrpc.Operations((operation,)),
             _send_initial_metadata(self._state))
         self._state.initial_metadata_allowed = False
         self._state.due.add(_SEND_INITIAL_METADATA_TOKEN)
       else:
         raise ValueError('Initial metadata no longer allowed!')
Esempio n. 8
0
 def _prepare(self, request, timeout, metadata):
   deadline, deadline_timespec, serialized_request, rendezvous = (
       _start_unary_request(request, timeout, self._request_serializer))
   if serialized_request is None:
     return None, None, None, None, rendezvous
   else:
     state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None)
     operations = (
         cygrpc.operation_send_initial_metadata(
             _common.metadata(metadata), _EMPTY_FLAGS),
         cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS),
         cygrpc.operation_send_close_from_client(_EMPTY_FLAGS),
         cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),
         cygrpc.operation_receive_message(_EMPTY_FLAGS),
         cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
     )
     return state, operations, deadline, deadline_timespec, None
Esempio n. 9
0
def _status(rpc_event, state, serialized_response):
  with state.condition:
    if state.client is not _CANCELLED:
      trailing_metadata = _common.metadata(state.trailing_metadata)
      code = _code(state)
      details = _details(state)
      operations = [
          cygrpc.operation_send_status_from_server(
              trailing_metadata, code, details, _EMPTY_FLAGS),
      ]
      if state.initial_metadata_allowed:
        operations.append(
            cygrpc.operation_send_initial_metadata(
                _EMPTY_METADATA, _EMPTY_FLAGS))
      if serialized_response is not None:
        operations.append(cygrpc.operation_send_message(
            serialized_response, _EMPTY_FLAGS))
      rpc_event.operation_call.start_batch(
          cygrpc.Operations(operations),
          _send_status_from_server(state, _SEND_STATUS_FROM_SERVER_TOKEN))
      state.statused = True
      state.due.add(_SEND_STATUS_FROM_SERVER_TOKEN)
Esempio n. 10
0
 def __call__(
     self, request_iterator, timeout=None, metadata=None, credentials=None):
   deadline, deadline_timespec = _deadline(timeout)
   state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None)
   call = self._create_managed_call(
       None, 0, self._method, None, deadline_timespec)
   if credentials is not None:
     call.set_credentials(credentials._credentials)
   event_handler = _event_handler(state, call, self._response_deserializer)
   with state.condition:
     call.start_batch(
         cygrpc.Operations(
             (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)),
         event_handler)
     operations = (
         cygrpc.operation_send_initial_metadata(
             _common.metadata(metadata), _EMPTY_FLAGS),
         cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
     )
     call.start_batch(cygrpc.Operations(operations), event_handler)
     _consume_request_iterator(
         request_iterator, state, call, self._request_serializer)
   return _Rendezvous(state, call, self._response_deserializer, deadline)
Esempio n. 11
0
def _status(rpc_event, state, serialized_response):
    with state.condition:
        if state.client is not _CANCELLED:
            trailing_metadata = _common.metadata(state.trailing_metadata)
            code = _completion_code(state)
            details = _details(state)
            operations = [
                cygrpc.operation_send_status_from_server(
                    trailing_metadata, code, details, _EMPTY_FLAGS),
            ]
            if state.initial_metadata_allowed:
                operations.append(
                    cygrpc.operation_send_initial_metadata(
                        _EMPTY_METADATA, _EMPTY_FLAGS))
            if serialized_response is not None:
                operations.append(
                    cygrpc.operation_send_message(serialized_response,
                                                  _EMPTY_FLAGS))
            rpc_event.operation_call.start_batch(
                cygrpc.Operations(operations),
                _send_status_from_server(state,
                                         _SEND_STATUS_FROM_SERVER_TOKEN))
            state.statused = True
            state.due.add(_SEND_STATUS_FROM_SERVER_TOKEN)