|
|
@ -41,6 +41,8 @@ from grpc.framework.foundation import logging_pool |
|
|
|
from grpc.framework.foundation import relay |
|
|
|
from grpc.framework.foundation import relay |
|
|
|
from grpc.framework.interfaces.links import links |
|
|
|
from grpc.framework.interfaces.links import links |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_IDENTITY = lambda x: x |
|
|
|
|
|
|
|
|
|
|
|
_STOP = _intermediary_low.Event.Kind.STOP |
|
|
|
_STOP = _intermediary_low.Event.Kind.STOP |
|
|
|
_WRITE = _intermediary_low.Event.Kind.WRITE_ACCEPTED |
|
|
|
_WRITE = _intermediary_low.Event.Kind.WRITE_ACCEPTED |
|
|
|
_COMPLETE = _intermediary_low.Event.Kind.COMPLETE_ACCEPTED |
|
|
|
_COMPLETE = _intermediary_low.Event.Kind.COMPLETE_ACCEPTED |
|
|
@ -95,11 +97,12 @@ def _no_longer_due(kind, rpc_state, key, rpc_states): |
|
|
|
class _Kernel(object): |
|
|
|
class _Kernel(object): |
|
|
|
|
|
|
|
|
|
|
|
def __init__( |
|
|
|
def __init__( |
|
|
|
self, channel, host, request_serializers, response_deserializers, |
|
|
|
self, channel, host, metadata_transformer, request_serializers, |
|
|
|
ticket_relay): |
|
|
|
response_deserializers, ticket_relay): |
|
|
|
self._lock = threading.Lock() |
|
|
|
self._lock = threading.Lock() |
|
|
|
self._channel = channel |
|
|
|
self._channel = channel |
|
|
|
self._host = host |
|
|
|
self._host = host |
|
|
|
|
|
|
|
self._metadata_transformer = metadata_transformer |
|
|
|
self._request_serializers = request_serializers |
|
|
|
self._request_serializers = request_serializers |
|
|
|
self._response_deserializers = response_deserializers |
|
|
|
self._response_deserializers = response_deserializers |
|
|
|
self._relay = ticket_relay |
|
|
|
self._relay = ticket_relay |
|
|
@ -225,20 +228,17 @@ class _Kernel(object): |
|
|
|
else: |
|
|
|
else: |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
request_serializer = self._request_serializers.get((group, method)) |
|
|
|
transformed_initial_metadata = self._metadata_transformer(initial_metadata) |
|
|
|
response_deserializer = self._response_deserializers.get((group, method)) |
|
|
|
request_serializer = self._request_serializers.get( |
|
|
|
if request_serializer is None or response_deserializer is None: |
|
|
|
(group, method), _IDENTITY) |
|
|
|
cancellation_ticket = links.Ticket( |
|
|
|
response_deserializer = self._response_deserializers.get( |
|
|
|
operation_id, 0, None, None, None, None, None, None, None, None, None, |
|
|
|
(group, method), _IDENTITY) |
|
|
|
None, links.Ticket.Termination.CANCELLATION) |
|
|
|
|
|
|
|
self._relay.add_value(cancellation_ticket) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
call = _intermediary_low.Call( |
|
|
|
call = _intermediary_low.Call( |
|
|
|
self._channel, self._completion_queue, '/%s/%s' % (group, method), |
|
|
|
self._channel, self._completion_queue, '/%s/%s' % (group, method), |
|
|
|
self._host, time.time() + timeout) |
|
|
|
self._host, time.time() + timeout) |
|
|
|
if initial_metadata is not None: |
|
|
|
if transformed_initial_metadata is not None: |
|
|
|
for metadata_key, metadata_value in initial_metadata: |
|
|
|
for metadata_key, metadata_value in transformed_initial_metadata: |
|
|
|
call.add_metadata(metadata_key, metadata_value) |
|
|
|
call.add_metadata(metadata_key, metadata_value) |
|
|
|
call.invoke(self._completion_queue, operation_id, operation_id) |
|
|
|
call.invoke(self._completion_queue, operation_id, operation_id) |
|
|
|
if payload is None: |
|
|
|
if payload is None: |
|
|
@ -336,10 +336,15 @@ class InvocationLink(links.Link, activated.Activated): |
|
|
|
class _InvocationLink(InvocationLink): |
|
|
|
class _InvocationLink(InvocationLink): |
|
|
|
|
|
|
|
|
|
|
|
def __init__( |
|
|
|
def __init__( |
|
|
|
self, channel, host, request_serializers, response_deserializers): |
|
|
|
self, channel, host, metadata_transformer, request_serializers, |
|
|
|
|
|
|
|
response_deserializers): |
|
|
|
self._relay = relay.relay(None) |
|
|
|
self._relay = relay.relay(None) |
|
|
|
self._kernel = _Kernel( |
|
|
|
self._kernel = _Kernel( |
|
|
|
channel, host, request_serializers, response_deserializers, self._relay) |
|
|
|
channel, host, |
|
|
|
|
|
|
|
_IDENTITY if metadata_transformer is None else metadata_transformer, |
|
|
|
|
|
|
|
{} if request_serializers is None else request_serializers, |
|
|
|
|
|
|
|
{} if response_deserializers is None else response_deserializers, |
|
|
|
|
|
|
|
self._relay) |
|
|
|
|
|
|
|
|
|
|
|
def _start(self): |
|
|
|
def _start(self): |
|
|
|
self._relay.start() |
|
|
|
self._relay.start() |
|
|
@ -376,12 +381,17 @@ class _InvocationLink(InvocationLink): |
|
|
|
self._stop() |
|
|
|
self._stop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def invocation_link(channel, host, request_serializers, response_deserializers): |
|
|
|
def invocation_link( |
|
|
|
|
|
|
|
channel, host, metadata_transformer, request_serializers, |
|
|
|
|
|
|
|
response_deserializers): |
|
|
|
"""Creates an InvocationLink. |
|
|
|
"""Creates an InvocationLink. |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
Args: |
|
|
|
channel: An _intermediary_low.Channel for use by the link. |
|
|
|
channel: An _intermediary_low.Channel for use by the link. |
|
|
|
host: The host to specify when invoking RPCs. |
|
|
|
host: The host to specify when invoking RPCs. |
|
|
|
|
|
|
|
metadata_transformer: A callable that takes an invocation-side initial |
|
|
|
|
|
|
|
metadata value and returns another metadata value to send in its place. |
|
|
|
|
|
|
|
May be None. |
|
|
|
request_serializers: A dict from group-method pair to request object |
|
|
|
request_serializers: A dict from group-method pair to request object |
|
|
|
serialization behavior. |
|
|
|
serialization behavior. |
|
|
|
response_deserializers: A dict from group-method pair to response object |
|
|
|
response_deserializers: A dict from group-method pair to response object |
|
|
@ -391,4 +401,5 @@ def invocation_link(channel, host, request_serializers, response_deserializers): |
|
|
|
An InvocationLink. |
|
|
|
An InvocationLink. |
|
|
|
""" |
|
|
|
""" |
|
|
|
return _InvocationLink( |
|
|
|
return _InvocationLink( |
|
|
|
channel, host, request_serializers, response_deserializers) |
|
|
|
channel, host, metadata_transformer, request_serializers, |
|
|
|
|
|
|
|
response_deserializers) |
|
|
|