Skip to content

Commit

Permalink
Add debug logging to gRPC extension class generation build steps
Browse files Browse the repository at this point in the history
Fixes #5490
  • Loading branch information
jamesnetherton committed Nov 9, 2023
1 parent 1806810 commit 91cf3cf
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.MethodParameterInfo;
import org.jboss.jandex.Type;
import org.jboss.logging.Logger;

class GrpcProcessor {

private static final Logger LOG = Logger.getLogger(GrpcProcessor.class);
private static final DotName BINDABLE_SERVICE_DOT_NAME = DotName.createSimple(BindableService.class.getName());
private static final DotName[] STUB_CLASS_DOT_NAMES = new DotName[] {
DotName.createSimple(AbstractAsyncStub.class.getName()),
Expand Down Expand Up @@ -102,7 +103,11 @@ void createBindableServiceBeans(
// Override the various sync and async methods so that requests can be intercepted and delegated to Camel routing
// This mimics similar logic in DefaultBindableServiceFactory that uses Javassist ProxyFactory & MethodHandler
for (ClassInfo service : bindableServiceImpls) {
String superClassName = service.name().toString();
String generatedClassName = superClassName + "QuarkusMethodHandler";

if (!Modifier.isAbstract(service.flags())) {
logDebugMessage("Ignoring BindableService %s as it is not an interface or abstract class", superClassName);
continue;
}

Expand All @@ -111,6 +116,7 @@ void createBindableServiceBeans(
* Not skipping it here results in randomly registering the Mutiny one or the right one.
* In case the Mutiny service one is registered, the client throws something like
* io.grpc.StatusRuntimeException: UNIMPLEMENTED */
logDebugMessage("Ignoring BindableService %s as it a Mutiny service", superClassName);
continue;
}

Expand All @@ -120,19 +126,19 @@ void createBindableServiceBeans(
.filter(className -> className.endsWith("AsyncService"))
.findFirst();
if (asyncServiceInterface.isEmpty()) {
logDebugMessage("Ignoring BindableService %s as it does not implement AsyncService", superClassName);
continue;
}

String superClassName = service.name().toString();
String generatedClassName = superClassName + "QuarkusMethodHandler";

// Register the service classes for reflection
reflectiveClass
.produce(ReflectiveClassBuildItem.builder(service.name().toString()).methods().build());
.produce(ReflectiveClassBuildItem.builder(superClassName).methods().build());
reflectiveClass.produce(
ReflectiveClassBuildItem.builder(service.enclosingClass().toString()).methods().build());
reflectiveClass.produce(ReflectiveClassBuildItem.builder(generatedClassName).methods().build());

logDebugMessage("Generating CamelQuarkusBindableService %s extending %s", generatedClassName, superClassName);

try (ClassCreator classCreator = ClassCreator.builder()
.classOutput(new GeneratedBeanGizmoAdaptor(generatedBean))
.className(generatedClassName)
Expand Down Expand Up @@ -185,6 +191,9 @@ void createBindableServiceBeans(

String returnType = method.returnType().name().toString();
try (MethodCreator methodCreator = classCreator.getMethodCreator(method.name(), returnType, params)) {
logDebugMessage("Creating service implementation for method %s in %s", method.name(),
generatedClassName);

method.exceptions()
.stream()
.map(type -> type.name().toString())
Expand Down Expand Up @@ -239,4 +248,10 @@ private ResultHandle generateGrpcDelegateMethod(ClassInfo classInfo, FieldCreato
ResultHandle resultHandle = methodCreator.readInstanceField(fieldCreator.getFieldDescriptor(), methodCreator.getThis());
return methodCreator.invokeVirtualMethod(method, resultHandle, methodParams);
}

private void logDebugMessage(String message, Object... params) {
if (LOG.isDebugEnabled()) {
LOG.debugf(message, params);
}
}
}

0 comments on commit 91cf3cf

Please sign in to comment.