RpcCallObserverInterceptor<S> class
abstract
An interceptor that sees every call start and end, for all four call shapes.
A subclass implements onCallStart, which returns the state it keeps for one call, and onCallEnd, which receives that state once with the RpcCallOutcome and the call's duration. For a streamed response the call ends when the stream does: when it is done, or when its consumer cancels it. The stream itself is passed through unchanged, pause and resume included.
The optional hooks: observes picks the calls it sees, contextFor changes the context the rest of the chain runs with, runCall runs the rest of the chain inside something (a zone), and onResponseMessage / onResponseError see each event of a streamed response.
final class SlowCallLog extends RpcCallObserverInterceptor<String> {
@override
String onCallStart(RpcCallInfo call, RpcMethodType type) =>
'${call.serviceName}.${call.methodName}';
@override
void onCallEnd(String name, RpcCallOutcome outcome, Duration duration) {
if (duration > const Duration(seconds: 1)) print('$name took $duration');
}
}
- Inheritance
-
- Object
- IRpcInterceptor
- RpcCallObserverInterceptor
Constructors
- RpcCallObserverInterceptor()
-
Creates the interceptor.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
check(
RpcCallInfo call) → FutureOr< void> -
Runs before this interceptor's method for unary, server-stream,
client-stream and bidirectional calls alike.
inherited
-
contextFor(
S state, RpcContext context) → RpcContext - The context the rest of the chain runs with. Unchanged by default.
-
interceptBidirectionalStream<
TRequest, TResponse> (RpcCallInfo call, Stream< TRequest> requests, RpcBidirectionalStreamNext<TRequest, TResponse> next) → Future<Stream< TResponse> > -
Bidirectional-stream call interceptor.
override
-
interceptClientStream<
TRequest, TResponse> (RpcCallInfo call, Stream< TRequest> requests, RpcClientStreamNext<TRequest, TResponse> next) → Future<TResponse> -
Client-stream call interceptor.
override
-
interceptServerStream<
TRequest, TResponse> (RpcCallInfo call, TRequest request, RpcServerStreamNext< TRequest, TResponse> next) → Future<Stream< TResponse> > -
Server-stream call interceptor.
override
-
interceptUnary<
TRequest, TResponse> (RpcCallInfo call, TRequest request, RpcUnaryNext< TRequest, TResponse> next) → Future<TResponse> -
Unary call interceptor.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
observes(
RpcCallInfo call, RpcMethodType type) → bool -
Whether this interceptor observes
call. A call it does not observe passes through untouched: no hook is called for it. True by default; on anRpcPeerEndpoint, whose one interceptor list runs both ways, an observer of one side checks RpcCallInfo.direction here. -
onCallEnd(
S state, RpcCallOutcome outcome, Duration duration) → void -
The call that onCallStart returned
statefor is over. Called exactly once per call. -
onCallStart(
RpcCallInfo call, RpcMethodType type) → S -
A call of
typereached this interceptor. Returns the state handed to every later hook of the same call. -
onResponseError(
S state, Object error, StackTrace stackTrace) → void - An error on a streamed response. The stream may go on; the call ends with the last one.
-
onResponseMessage(
S state) → void - A message of a streamed response.
-
runCall<
T> (S state, Future< T> body()) → Future<T> -
Runs
body, the rest of the chain, forstate. Calls it by default; override to run it inside a zone. Must return whatbodyreturns, or rethrow what it throws. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited