14 """The base interface of RPC Framework.
16 Implementations of this interface support the conduct of "operations":
17 exchanges between two distinct ends of an arbitrary number of data payloads
18 and metadata such as a name for the operation, initial and terminal metadata
19 in each direction, and flow control. These operations may be used for transfers
20 of data, remote procedure calls, status indication, or anything else
35 """Indicates that an unrecognized operation has been called.
38 code: A code value to communicate to the other side of the operation
39 along with indication of operation termination. May be None.
40 details: A details value to communicate to the other side of the
41 operation along with indication of operation termination. May be None.
48 code: A code value to communicate to the other side of the operation
49 along with indication of operation termination. May be None.
50 details: A details value to communicate to the other side of the
51 operation along with indication of operation termination. May be None.
53 super(NoSuchMethodError, self).
__init__()
59 """The outcome of an operation.
62 kind: A Kind value coarsely identifying how the operation terminated.
63 code: An application-specific code value or None if no such value was
65 details: An application-specific details value or None if no such value was
71 """Ways in which an operation can terminate."""
73 COMPLETED =
'completed'
74 CANCELLED =
'cancelled'
76 LOCAL_SHUTDOWN =
'local shutdown'
77 REMOTE_SHUTDOWN =
'remote shutdown'
78 RECEPTION_FAILURE =
'reception failure'
79 TRANSMISSION_FAILURE =
'transmission failure'
80 LOCAL_FAILURE =
'local failure'
81 REMOTE_FAILURE =
'remote failure'
85 """An aggregate of the values exchanged upon operation completion.
88 terminal_metadata: A terminal metadata value for the operaton.
89 code: A code value for the operation.
90 message: A message value for the operation.
94 class OperationContext(six.with_metaclass(abc.ABCMeta)):
95 """Provides operation-related information and action."""
99 """Indicates the operation's outcome (or that the operation is ongoing).
102 None if the operation is still active or the Outcome value for the
103 operation if it has terminated.
105 raise NotImplementedError()
109 """Adds a function to be called upon operation termination.
112 callback: A callable to be passed an Outcome value on operation
116 None if the operation has not yet terminated and the passed callback will
117 later be called when it does terminate, or if the operation has already
118 terminated an Outcome value describing the operation termination and the
119 passed callback will not be called as a result of this method call.
121 raise NotImplementedError()
125 """Describes the length of allowed time remaining for the operation.
128 A nonnegative float indicating the length of allowed time in seconds
129 remaining for the operation to complete before it is considered to have
130 timed out. Zero is returned if the operation has terminated.
132 raise NotImplementedError()
136 """Cancels the operation if the operation has not yet terminated."""
137 raise NotImplementedError()
141 """Indicates that the operation has failed.
144 exception: An exception germane to the operation failure. May be None.
146 raise NotImplementedError()
150 """An interface through which to participate in an operation."""
154 initial_metadata=None,
158 """Progresses the operation.
161 initial_metadata: An initial metadata value. Only one may ever be
162 communicated in each direction for an operation, and they must be
163 communicated no later than either the first payload or the completion.
164 payload: A payload value.
165 completion: A Completion value. May only ever be non-None once in either
166 direction, and no payloads may be passed after it has been communicated.
167 allowance: A positive integer communicating the number of additional
168 payloads allowed to be passed by the remote side of the operation.
170 raise NotImplementedError()
174 """A means of receiving protocol values during an operation."""
178 """Accepts the protocol context object for the operation.
181 protocol_context: The protocol context object for the operation.
183 raise NotImplementedError()
187 """Describes customer code's interest in values from the other side.
190 kind: A Kind value describing the overall kind of this value.
191 termination_callback: A callable to be passed the Outcome associated with
192 the operation after it has terminated. Must be non-None if kind is
193 Kind.TERMINATION_ONLY. Must be None otherwise.
194 allowance: A callable behavior that accepts positive integers representing
195 the number of additional payloads allowed to be passed to the other side
196 of the operation. Must be None if kind is Kind.FULL. Must not be None
198 operator: An Operator to be passed values from the other side of the
199 operation. Must be non-None if kind is Kind.FULL. Must be None otherwise.
200 protocol_receiver: A ProtocolReceiver to be passed protocol objects as they
201 become available during the operation. Must be non-None if kind is
209 TERMINATION_ONLY =
'termination only'
214 """Interface for service implementations."""
217 def service(self, group, method, context, output_operator):
218 """Services an operation.
221 group: The group identifier of the operation to be serviced.
222 method: The method identifier of the operation to be serviced.
223 context: An OperationContext object affording contextual information and
225 output_operator: An Operator that will accept output values of the
229 A Subscription via which this object may or may not accept more values of
233 NoSuchMethodError: If this Servicer does not handle operations with the
234 given group and method.
235 abandonment.Abandoned: If the operation has been aborted and there no
236 longer is any reason to service the operation.
238 raise NotImplementedError()
241 class End(six.with_metaclass(abc.ABCMeta)):
242 """Common type for entry-point objects on both sides of an operation."""
246 """Starts this object's service of operations."""
247 raise NotImplementedError()
251 """Stops this object's service of operations.
253 This object will refuse service of new operations as soon as this method is
254 called but operations under way at the time of the call may be given a
255 grace period during which they are allowed to finish.
258 grace: A duration of time in seconds to allow ongoing operations to
259 terminate before being forcefully terminated by the stopping of this
260 End. May be zero to terminate all ongoing operations and immediately
264 A threading.Event that will be set to indicate all operations having
265 terminated and this End having completely stopped. The returned event
266 may not be set until after the full grace period (if some ongoing
267 operation continues for the full length of the period) or it may be set
268 much sooner (if for example this End had no operations in progress at
269 the time its stop method was called).
271 raise NotImplementedError()
279 initial_metadata=None,
282 protocol_options=None):
283 """Commences an operation.
286 group: The group identifier of the invoked operation.
287 method: The method identifier of the invoked operation.
288 subscription: A Subscription to which the results of the operation will be
290 timeout: A length of time in seconds to allow for the operation.
291 initial_metadata: An initial metadata value to be sent to the other side
292 of the operation. May be None if the initial metadata will be later
293 passed via the returned operator or if there will be no initial metadata
295 payload: An initial payload for the operation.
296 completion: A Completion value indicating the end of transmission to the
297 other side of the operation.
298 protocol_options: A value specified by the provider of a Base interface
299 implementation affording custom state and behavior.
302 A pair of objects affording information about the operation and action
303 continuing the operation. The first element of the returned pair is an
304 OperationContext for the operation and the second element of the
305 returned pair is an Operator to which operation values not passed in
306 this call should later be passed.
308 raise NotImplementedError()
312 """Reports the number of terminated operations broken down by outcome.
315 A dictionary from Outcome.Kind value to an integer identifying the number
316 of operations that terminated with that outcome kind.
318 raise NotImplementedError()
322 """Adds an action to be called when this End has no ongoing operations.
325 action: A callable that accepts no arguments.
327 raise NotImplementedError()