public final class Invocation
extends java.lang.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.service().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 |
---|---|
java.util.List<?> |
arguments() |
java.lang.Object |
instance()
The instance of
service . |
java.lang.reflect.Method |
method() |
static <T> Invocation |
of(java.lang.Class<T> service,
T instance,
java.lang.reflect.Method method,
java.util.List<?> arguments) |
static Invocation |
of(java.lang.reflect.Method method,
java.util.List<?> arguments)
Deprecated.
|
java.lang.Class<?> |
service() |
java.lang.String |
toString() |
public static <T> Invocation of(java.lang.Class<T> service, T instance, java.lang.reflect.Method method, java.util.List<?> arguments)
@Deprecated public static Invocation of(java.lang.reflect.Method method, java.util.List<?> arguments)
public java.lang.Class<?> service()
@Nullable public java.lang.Object instance()
service
.
This will never be null when created by Retrofit. Null will only be returned when created
by of(Method, List)
.
public java.lang.reflect.Method method()
public java.util.List<?> arguments()
public java.lang.String toString()
toString
in class java.lang.Object