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.lang.String |
annotationUrl()
|
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 <T> Invocation |
of(java.lang.Class<T> service,
T instance,
java.lang.reflect.Method method,
java.util.List<?> arguments,
java.lang.String annotationUrl) |
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, @Nullable java.lang.String annotationUrl)
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()
@Nullable public java.lang.String annotationUrl()
@GET or
@POST.
If the method uses the @Path annotation, this is the template URL
before path substitution, as it occurs in source code.
This value will be null if one of the method's parameter is annotated
@Url. It will also be null if this Invocation was created using one
of the factory-functions that don't have this value.
public java.lang.String toString()
toString in class java.lang.Object