Skip to content

Commit

Permalink
Merge pull request quarkusio#45312 from geoand/rr-recorder-mh
Browse files Browse the repository at this point in the history
Use MethodHandles for constructing RESTEasy Reactive invokers
  • Loading branch information
geoand authored Jan 3, 2025
2 parents ab524c3 + 4174a90 commit 39c5261
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import static io.quarkus.vertx.http.runtime.security.HttpSecurityRecorder.DefaultAuthFailureHandler.removeMarkAsOtherAuthenticationFailure;

import java.io.Closeable;
import java.lang.reflect.InvocationTargetException;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -23,7 +25,6 @@
import jakarta.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.common.core.SingletonBeanFactory;
import org.jboss.resteasy.reactive.common.model.ResourceContextResolver;
import org.jboss.resteasy.reactive.common.model.ResourceExceptionMapper;
Expand Down Expand Up @@ -85,16 +86,17 @@
@Recorder
public class ResteasyReactiveRecorder extends ResteasyReactiveCommonRecorder implements EndpointInvokerFactory {

static final Logger logger = Logger.getLogger("io.quarkus");
private static final MethodType VOID_TYPE = MethodType.methodType(void.class);
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();

public static final Supplier<Executor> EXECUTOR_SUPPLIER = new Supplier<Executor>() {
public static final Supplier<Executor> EXECUTOR_SUPPLIER = new Supplier<>() {
@Override
public Executor get() {
return ExecutorRecorder.getCurrent();
}
};

public static final Supplier<Executor> VTHREAD_EXECUTOR_SUPPLIER = new Supplier<Executor>() {
public static final Supplier<Executor> VTHREAD_EXECUTOR_SUPPLIER = new Supplier<>() {
@Override
public Executor get() {
return VirtualThreadsRecorder.getCurrent();
Expand Down Expand Up @@ -127,7 +129,7 @@ public boolean isBlockingAllowed() {
}
});

Consumer<Closeable> closeTaskHandler = new Consumer<Closeable>() {
Consumer<Closeable> closeTaskHandler = new Consumer<>() {
@Override
public void accept(Closeable closeable) {
shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(closeable));
Expand Down Expand Up @@ -198,7 +200,7 @@ public Handler<RoutingContext> failureHandler(RuntimeValue<RestInitialHandler> r
boolean proactive) {
final RestInitialHandler restInitialHandler = restInitialHandlerRuntimeValue.getValue();
// process auth failures with abort handlers
return new Handler<RoutingContext>() {
return new Handler<>() {
@Override
public void handle(RoutingContext event) {

Expand Down Expand Up @@ -270,7 +272,7 @@ public Supplier<Application> handleApplication(final Class<? extends Application
final boolean singletonClassesEmpty) {
Supplier<Application> applicationSupplier;
if (singletonClassesEmpty) {
applicationSupplier = new Supplier<Application>() {
applicationSupplier = new Supplier<>() {
@Override
public Application get() {
try {
Expand All @@ -286,7 +288,7 @@ public Application get() {
for (Object i : application.getSingletons()) {
SingletonBeanFactory.setInstance(i.getClass().getName(), i);
}
applicationSupplier = new Supplier<Application>() {
applicationSupplier = new Supplier<>() {

@Override
public Application get() {
Expand All @@ -312,23 +314,25 @@ public void registerContextResolver(ContextResolvers contextResolvers, String st
}

@Override
public Supplier<EndpointInvoker> invoker(String baseName) {
return new Supplier<EndpointInvoker>() {
public Supplier<EndpointInvoker> invoker(String invokerClassName) {
return new Supplier<>() {
@Override
public EndpointInvoker get() {
try {
return (EndpointInvoker) loadClass(baseName).getDeclaredConstructor().newInstance();
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException
| InvocationTargetException e) {
throw new RuntimeException("Unable to generate endpoint invoker", e);
Class<Object> invokerClass = loadClass(invokerClassName);
return (EndpointInvoker) LOOKUP.findConstructor(invokerClass, VOID_TYPE).invoke();
} catch (RuntimeException | Error e) {
throw e;
} catch (Throwable t) {
throw new UndeclaredThrowableException(t);
}

}
};
}

public Function<Class<?>, BeanFactory<?>> factoryCreator(BeanContainer container) {
return new Function<Class<?>, BeanFactory<?>>() {
return new Function<>() {
@Override
public BeanFactory<?> apply(Class<?> aClass) {
return new ArcBeanFactory<>(aClass, container);
Expand Down

0 comments on commit 39c5261

Please sign in to comment.