1
1
package io .camunda .zeebe .spring .client .annotation .processor ;
2
2
3
+ import static org .springframework .util .ReflectionUtils .doWithMethods ;
4
+
3
5
import io .camunda .zeebe .client .ZeebeClient ;
4
6
import io .camunda .zeebe .spring .client .annotation .JobWorker ;
5
7
import io .camunda .zeebe .spring .client .annotation .ZeebeWorker ;
8
10
import io .camunda .zeebe .spring .client .bean .ClassInfo ;
9
11
import io .camunda .zeebe .spring .client .bean .MethodInfo ;
10
12
import io .camunda .zeebe .spring .client .jobhandling .JobWorkerManager ;
11
- import org .slf4j .Logger ;
12
- import org .slf4j .LoggerFactory ;
13
- import org .springframework .util .ReflectionUtils ;
14
-
15
13
import java .lang .invoke .MethodHandles ;
16
14
import java .util .ArrayList ;
17
15
import java .util .List ;
18
16
import java .util .Optional ;
19
-
20
- import static org .springframework .util .ReflectionUtils .doWithMethods ;
17
+ import org .slf4j .Logger ;
18
+ import org .slf4j .LoggerFactory ;
19
+ import org .springframework .util .ReflectionUtils ;
21
20
22
21
/**
23
22
* Always created by {@link AnnotationProcessorConfiguration}
24
23
*
25
- * Triggered by {@link ZeebeAnnotationProcessorRegistry#postProcessAfterInitialization(Object, String)} to add Handler subscriptions for {@link ZeebeWorker}
26
- * method-annotations.
24
+ * <p> Triggered by {@link ZeebeAnnotationProcessorRegistry#postProcessAfterInitialization(Object,
25
+ * String)} to add Handler subscriptions for {@link ZeebeWorker} method-annotations.
27
26
*/
28
27
public class ZeebeWorkerAnnotationProcessor extends AbstractZeebeAnnotationProcessor {
29
28
30
- private static final Logger LOGGER = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
29
+ private static final Logger LOGGER =
30
+ LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
31
31
32
32
private final JobWorkerManager jobWorkerManager ;
33
33
@@ -36,9 +36,11 @@ public class ZeebeWorkerAnnotationProcessor extends AbstractZeebeAnnotationProce
36
36
private String defaultWorkerType ;
37
37
private String defaultWorkerName ;
38
38
39
- public ZeebeWorkerAnnotationProcessor (final JobWorkerManager jobWorkerFactory ,
40
- final List <ZeebeWorkerValueCustomizer > zeebeWorkerValueCustomizers ,
41
- final String defaultWorkerType , final String defaultJobWorkerName ) {
39
+ public ZeebeWorkerAnnotationProcessor (
40
+ final JobWorkerManager jobWorkerFactory ,
41
+ final List <ZeebeWorkerValueCustomizer > zeebeWorkerValueCustomizers ,
42
+ final String defaultWorkerType ,
43
+ final String defaultJobWorkerName ) {
42
44
this .jobWorkerManager = jobWorkerFactory ;
43
45
this .zeebeWorkerValueCustomizers = zeebeWorkerValueCustomizers ;
44
46
this .defaultWorkerType = defaultWorkerType ;
@@ -47,78 +49,92 @@ public ZeebeWorkerAnnotationProcessor(final JobWorkerManager jobWorkerFactory,
47
49
48
50
@ Override
49
51
public boolean isApplicableFor (ClassInfo beanInfo ) {
50
- return beanInfo .hasMethodAnnotation (JobWorker .class ) || beanInfo .hasMethodAnnotation (ZeebeWorker .class );
52
+ return beanInfo .hasMethodAnnotation (JobWorker .class )
53
+ || beanInfo .hasMethodAnnotation (ZeebeWorker .class );
51
54
}
52
55
53
56
@ Override
54
57
public void configureFor (ClassInfo beanInfo ) {
55
58
List <ZeebeWorkerValue > newZeebeWorkerValues = new ArrayList <>();
56
59
57
60
doWithMethods (
58
- beanInfo .getTargetClass (),
59
- method -> readJobWorkerAnnotationForMethod (beanInfo .toMethodInfo (method )).ifPresent (newZeebeWorkerValues ::add ),
60
- ReflectionUtils .USER_DECLARED_METHODS );
61
-
62
- LOGGER .info ("Configuring {} Zeebe worker(s) of bean '{}': {}" , newZeebeWorkerValues .size (), beanInfo .getBeanName (), newZeebeWorkerValues );
61
+ beanInfo .getTargetClass (),
62
+ method ->
63
+ readJobWorkerAnnotationForMethod (beanInfo .toMethodInfo (method ))
64
+ .ifPresent (newZeebeWorkerValues ::add ),
65
+ ReflectionUtils .USER_DECLARED_METHODS );
66
+
67
+ LOGGER .info (
68
+ "Configuring {} Zeebe worker(s) of bean '{}': {}" ,
69
+ newZeebeWorkerValues .size (),
70
+ beanInfo .getBeanName (),
71
+ newZeebeWorkerValues );
63
72
zeebeWorkerValues .addAll (newZeebeWorkerValues );
64
73
}
65
74
66
75
public Optional <ZeebeWorkerValue > readJobWorkerAnnotationForMethod (final MethodInfo methodInfo ) {
67
76
Optional <JobWorker > methodAnnotation = methodInfo .getAnnotation (JobWorker .class );
68
77
if (methodAnnotation .isPresent ()) {
69
78
JobWorker annotation = methodAnnotation .get ();
70
- return Optional .of (new ZeebeWorkerValue ()
71
- .methodInfo (methodInfo )
72
- .type (annotation .type ())
73
- .timeout (annotation .timeout ())
74
- .maxJobsActive (annotation .maxJobsActive ())
75
- .pollInterval (annotation .pollInterval ())
76
- .autoComplete (annotation .autoComplete ())
77
- .requestTimeout (annotation .requestTimeout ())
78
- .enabled (annotation .enabled ())
79
-
80
- // TODO Get rid of those initialize methods but add the attributes as values onto the worker and then auto-initialize stuff when opening the worker
81
- .initializeName (annotation .name (), methodInfo , defaultWorkerName )
82
- .initializeFetchVariables (annotation .fetchAllVariables (), annotation .fetchVariables (), methodInfo )
83
- .initializeJobType (annotation .type (), methodInfo , defaultWorkerType ));
79
+ return Optional .of (
80
+ new ZeebeWorkerValue ()
81
+ .methodInfo (methodInfo )
82
+ .type (annotation .type ())
83
+ .timeout (annotation .timeout ())
84
+ .maxJobsActive (annotation .maxJobsActive ())
85
+ .pollInterval (annotation .pollInterval ())
86
+ .autoComplete (annotation .autoComplete ())
87
+ .requestTimeout (annotation .requestTimeout ())
88
+ .enabled (annotation .enabled ())
89
+
90
+ // TODO Get rid of those initialize methods but add the attributes as values onto the
91
+ // worker and then auto-initialize stuff when opening the worker
92
+ .initializeName (annotation .name (), methodInfo , defaultWorkerName )
93
+ .initializeFetchVariables (
94
+ annotation .fetchAllVariables (), annotation .fetchVariables (), methodInfo )
95
+ .initializeJobType (annotation .type (), methodInfo , defaultWorkerType ));
84
96
} else {
85
97
Optional <ZeebeWorker > legacyAnnotation = methodInfo .getAnnotation (ZeebeWorker .class );
86
98
if (legacyAnnotation .isPresent ()) {
87
99
ZeebeWorker annotation = legacyAnnotation .get ();
88
- return Optional .of (new ZeebeWorkerValue ()
89
- .methodInfo (methodInfo )
90
- .type (annotation .type ())
91
- .timeout (annotation .timeout ())
92
- .maxJobsActive (annotation .maxJobsActive ())
93
- .pollInterval (annotation .pollInterval ())
94
- .autoComplete (annotation .autoComplete ())
95
- .requestTimeout (annotation .requestTimeout ())
96
- .enabled (annotation .enabled ())
97
-
98
- // TODO Get rid of those initialize methods but add the attributes as values onto the worker and then auto-initialize stuff when opening the worker
99
- .initializeName (annotation .name (), methodInfo , defaultWorkerName )
100
- .initializeFetchVariables (annotation .forceFetchAllVariables (), annotation .fetchVariables (), methodInfo )
101
- .initializeJobType (annotation .type (), methodInfo , defaultWorkerType ));
100
+ return Optional .of (
101
+ new ZeebeWorkerValue ()
102
+ .methodInfo (methodInfo )
103
+ .type (annotation .type ())
104
+ .timeout (annotation .timeout ())
105
+ .maxJobsActive (annotation .maxJobsActive ())
106
+ .pollInterval (annotation .pollInterval ())
107
+ .autoComplete (annotation .autoComplete ())
108
+ .requestTimeout (annotation .requestTimeout ())
109
+ .enabled (annotation .enabled ())
110
+
111
+ // TODO Get rid of those initialize methods but add the attributes as values onto
112
+ // the worker and then auto-initialize stuff when opening the worker
113
+ .initializeName (annotation .name (), methodInfo , defaultWorkerName )
114
+ .initializeFetchVariables (
115
+ annotation .forceFetchAllVariables (), annotation .fetchVariables (), methodInfo )
116
+ .initializeJobType (annotation .type (), methodInfo , defaultWorkerType ));
102
117
}
103
118
}
104
119
return Optional .empty ();
105
120
}
106
121
107
122
@ Override
108
123
public void start (ZeebeClient client ) {
109
- zeebeWorkerValues
110
- .stream ()
111
- .peek (zeebeWorkerValue -> zeebeWorkerValueCustomizers .forEach (customizer -> customizer .customize (zeebeWorkerValue )))
112
- .filter (ZeebeWorkerValue ::getEnabled )
113
- .forEach (
114
- zeebeWorkerValue -> {
115
- jobWorkerManager .openWorker (client , zeebeWorkerValue );
116
- });
124
+ zeebeWorkerValues .stream ()
125
+ .peek (
126
+ zeebeWorkerValue ->
127
+ zeebeWorkerValueCustomizers .forEach (
128
+ customizer -> customizer .customize (zeebeWorkerValue )))
129
+ .filter (ZeebeWorkerValue ::getEnabled )
130
+ .forEach (
131
+ zeebeWorkerValue -> {
132
+ jobWorkerManager .openWorker (client , zeebeWorkerValue );
133
+ });
117
134
}
118
135
119
136
@ Override
120
137
public void stop (ZeebeClient zeebeClient ) {
121
138
jobWorkerManager .closeAllOpenWorkers ();
122
139
}
123
-
124
140
}
0 commit comments