|
9 | 9 | import java.util.Map;
|
10 | 10 | import java.util.function.Consumer;
|
11 | 11 | import java.util.function.Function;
|
| 12 | +import java.util.function.Predicate; |
12 | 13 | import java.util.regex.Matcher;
|
13 | 14 | import java.util.regex.Pattern;
|
14 | 15 |
|
|
36 | 37 | import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
|
37 | 38 | import io.quarkus.arc.deployment.TransformedAnnotationsBuildItem;
|
38 | 39 | import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
|
| 40 | +import io.quarkus.arc.processor.Annotations; |
39 | 41 | import io.quarkus.arc.processor.BeanInfo;
|
40 | 42 | import io.quarkus.arc.processor.BuiltinScope;
|
41 | 43 | import io.quarkus.arc.processor.DotNames;
|
|
47 | 49 | import io.quarkus.deployment.builditem.FeatureBuildItem;
|
48 | 50 | import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
|
49 | 51 | import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
|
| 52 | +import io.quarkus.deployment.execannotations.ExecutionModelAnnotationsAllowedBuildItem; |
50 | 53 | import io.quarkus.gizmo.BytecodeCreator;
|
51 | 54 | import io.quarkus.gizmo.CatchBlockCreator;
|
52 | 55 | import io.quarkus.gizmo.ClassCreator;
|
@@ -117,6 +120,18 @@ void unremovableBeans(BuildProducer<UnremovableBeanBuildItem> unremovableBeans)
|
117 | 120 | unremovableBeans.produce(UnremovableBeanBuildItem.beanTypes(TextMessageCodec.class));
|
118 | 121 | }
|
119 | 122 |
|
| 123 | + @BuildStep |
| 124 | + ExecutionModelAnnotationsAllowedBuildItem executionModelAnnotations( |
| 125 | + TransformedAnnotationsBuildItem transformedAnnotations) { |
| 126 | + return new ExecutionModelAnnotationsAllowedBuildItem(new Predicate<MethodInfo>() { |
| 127 | + @Override |
| 128 | + public boolean test(MethodInfo method) { |
| 129 | + return Annotations.containsAny(transformedAnnotations.getAnnotations(method), |
| 130 | + WebSocketDotNames.CALLBACK_ANNOTATIONS); |
| 131 | + } |
| 132 | + }); |
| 133 | + } |
| 134 | + |
120 | 135 | @BuildStep
|
121 | 136 | public void collectEndpoints(BeanArchiveIndexBuildItem beanArchiveIndex,
|
122 | 137 | BeanDiscoveryFinishedBuildItem beanDiscoveryFinished,
|
@@ -1006,7 +1021,8 @@ private List<Callback> findErrorHandlers(IndexView index, ClassInfo beanClass, C
|
1006 | 1021 | List<Callback> errorHandlers = new ArrayList<>();
|
1007 | 1022 | for (AnnotationInstance annotation : annotations) {
|
1008 | 1023 | MethodInfo method = annotation.target().asMethod();
|
1009 |
| - Callback callback = new Callback(annotation, method, executionModel(method), callbackArguments, |
| 1024 | + Callback callback = new Callback(annotation, method, executionModel(method, transformedAnnotations), |
| 1025 | + callbackArguments, |
1010 | 1026 | transformedAnnotations, endpointPath, index);
|
1011 | 1027 | long errorArguments = callback.arguments.stream().filter(ca -> ca instanceof ErrorCallbackArgument).count();
|
1012 | 1028 | if (errorArguments != 1) {
|
@@ -1052,7 +1068,8 @@ private Callback findCallback(IndexView index, ClassInfo beanClass, DotName anno
|
1052 | 1068 | } else if (annotations.size() == 1) {
|
1053 | 1069 | AnnotationInstance annotation = annotations.get(0);
|
1054 | 1070 | MethodInfo method = annotation.target().asMethod();
|
1055 |
| - Callback callback = new Callback(annotation, method, executionModel(method), callbackArguments, |
| 1071 | + Callback callback = new Callback(annotation, method, executionModel(method, transformedAnnotations), |
| 1072 | + callbackArguments, |
1056 | 1073 | transformedAnnotations, endpointPath, index);
|
1057 | 1074 | long messageArguments = callback.arguments.stream().filter(ca -> ca instanceof MessageCallbackArgument).count();
|
1058 | 1075 | if (callback.acceptsMessage()) {
|
@@ -1081,13 +1098,16 @@ private Callback findCallback(IndexView index, ClassInfo beanClass, DotName anno
|
1081 | 1098 | String.format("There can be only one callback annotated with %s declared on %s", annotationName, beanClass));
|
1082 | 1099 | }
|
1083 | 1100 |
|
1084 |
| - ExecutionModel executionModel(MethodInfo method) { |
1085 |
| - if (hasBlockingSignature(method)) { |
1086 |
| - return method.hasDeclaredAnnotation(WebSocketDotNames.RUN_ON_VIRTUAL_THREAD) ? ExecutionModel.VIRTUAL_THREAD |
1087 |
| - : ExecutionModel.WORKER_THREAD; |
| 1101 | + ExecutionModel executionModel(MethodInfo method, TransformedAnnotationsBuildItem transformedAnnotations) { |
| 1102 | + if (transformedAnnotations.hasAnnotation(method, WebSocketDotNames.RUN_ON_VIRTUAL_THREAD)) { |
| 1103 | + return ExecutionModel.VIRTUAL_THREAD; |
| 1104 | + } else if (transformedAnnotations.hasAnnotation(method, WebSocketDotNames.BLOCKING)) { |
| 1105 | + return ExecutionModel.WORKER_THREAD; |
| 1106 | + } else if (transformedAnnotations.hasAnnotation(method, WebSocketDotNames.NON_BLOCKING)) { |
| 1107 | + return ExecutionModel.EVENT_LOOP; |
| 1108 | + } else { |
| 1109 | + return hasBlockingSignature(method) ? ExecutionModel.WORKER_THREAD : ExecutionModel.EVENT_LOOP; |
1088 | 1110 | }
|
1089 |
| - return method.hasDeclaredAnnotation(WebSocketDotNames.BLOCKING) ? ExecutionModel.WORKER_THREAD |
1090 |
| - : ExecutionModel.EVENT_LOOP; |
1091 | 1111 | }
|
1092 | 1112 |
|
1093 | 1113 | boolean hasBlockingSignature(MethodInfo method) {
|
|
0 commit comments