public final class Invocation extends Object
Retrofit automatically adds an invocation to each OkHttp request as a tag. You can retrieve the invocation in an OkHttp interceptor for metrics and monitoring.
class InvocationLogger implements Interceptor {
@Override public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Invocation invocation = request.tag(Invocation.class);
if (invocation != null) {
System.out.printf("%s.%s %s%n",
invocation.method().getDeclaringClass().getSimpleName(),
invocation.method().getName(), invocation.arguments());
}
return chain.proceed(request);
}
}
Note: use caution when examining an invocation's arguments. Although the
arguments list is unmodifiable, the arguments themselves may be mutable. They may also be unsafe
for concurrent access. For best results declare Retrofit service interfaces using only immutable
types for parameters!Modifier and Type | Method and Description |
---|---|
List<?> |
arguments() |
Method |
method() |
static Invocation |
of(Method method,
List<?> arguments) |
String |
toString() |
Copyright © 2020 Square, Inc.. All rights reserved.