use of com.netflix.titus.common.framework.fit.FitInjection in project titus-control-plane by Netflix.
the class FitInvocationHandler method newProxy.
public static <I> I newProxy(Object delegate, FitInjection injection) {
List<Class<?>> interfaces = ReflectionExt.findAllInterfaces(delegate.getClass());
Preconditions.checkArgument(interfaces.size() == 1, "%s expected to implement exactly one interface", delegate.getClass().getName());
Class<?> interf = interfaces.get(0);
Map<Method, Function<Object[], Object>> handlers = new HashMap<>();
for (Method method : interf.getMethods()) {
Class<?> returnType = method.getReturnType();
if (returnType.isAssignableFrom(CompletableFuture.class)) {
handlers.put(method, args -> handleCompletableFuture(injection, method, delegate, args));
} else if (returnType.isAssignableFrom(ListenableFuture.class)) {
handlers.put(method, args -> handleListenableFuture(injection, method, delegate, args));
} else if (returnType.isAssignableFrom(Observable.class)) {
handlers.put(method, args -> handleObservable(injection, method, delegate, args));
} else {
handlers.put(method, args -> handleSynchronous(injection, method, delegate, args));
}
}
return (I) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { interf }, new FitInvocationHandler(delegate, handlers));
}
Aggregations