in invoker/core/src/main/java/com/google/cloud/functions/invoker/TypedFunctionExecutor.java [37:80]
public static TypedFunctionExecutor forClass(Class<?> functionClass) {
if (!TypedFunction.class.isAssignableFrom(functionClass)) {
throw new RuntimeException(
"Class "
+ functionClass.getName()
+ " does not implement "
+ TypedFunction.class.getName());
}
@SuppressWarnings("unchecked")
Class<? extends TypedFunction<?, ?>> typedFunctionClass =
(Class<? extends TypedFunction<?, ?>>) functionClass.asSubclass(TypedFunction.class);
Optional<Type> argType = handlerTypeArgument(typedFunctionClass);
if (argType.isEmpty()) {
throw new RuntimeException(
"Class "
+ typedFunctionClass.getName()
+ " does not implement "
+ TypedFunction.class.getName());
}
TypedFunction<?, ?> typedFunction;
try {
typedFunction = typedFunctionClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(
"Class "
+ typedFunctionClass.getName()
+ " must declare a valid default constructor to be usable as a strongly typed"
+ " function. Could not use constructor: "
+ e.toString());
}
WireFormat format = typedFunction.getWireFormat();
if (format == null) {
format = LazyDefaultFormatHolder.defaultFormat;
}
@SuppressWarnings("unchecked")
TypedFunctionExecutor executor =
new TypedFunctionExecutor(
argType.orElseThrow(), (TypedFunction<Object, Object>) typedFunction, format);
return executor;
}