23
23
import com .google .common .base .Preconditions ;
24
24
import io .opentracing .Tracer ;
25
25
import io .temporal .client .WorkflowClient ;
26
+ import io .temporal .common .Experimental ;
26
27
import io .temporal .common .metadata .POJOWorkflowImplMetadata ;
27
28
import io .temporal .common .metadata .POJOWorkflowMethodMetadata ;
28
29
import io .temporal .spring .boot .ActivityImpl ;
@@ -74,6 +75,7 @@ public class WorkersTemplate implements BeanFactoryAware, EnvironmentAware {
74
75
75
76
private WorkerFactory workerFactory ;
76
77
private Collection <Worker > workers ;
78
+ private final Map <String , RegisteredInfo > registeredInfo = new HashMap <>();
77
79
78
80
public WorkersTemplate (
79
81
@ Nonnull TemporalProperties properties ,
@@ -111,6 +113,15 @@ public Collection<Worker> getWorkers() {
111
113
return workers ;
112
114
}
113
115
116
+ /** Return information on registered workflow and activity types per task queue */
117
+ @ Experimental
118
+ public Map <String , RegisteredInfo > getRegisteredInfo () {
119
+ if (workers == null ) {
120
+ this .workers = createWorkers (getWorkerFactory ());
121
+ }
122
+ return registeredInfo ;
123
+ }
124
+
114
125
WorkerFactory createWorkerFactory (WorkflowClient workflowClient ) {
115
126
if (testWorkflowEnvironment != null ) {
116
127
return testWorkflowEnvironment .getWorkerFactory ();
@@ -170,7 +181,7 @@ private void configureWorkflowImplementationsByTaskQueue(
170
181
worker = createNewWorker (taskQueue , null , workers );
171
182
}
172
183
173
- configureWorkflowImplementationAutoDiscovery (worker , clazz , null );
184
+ configureWorkflowImplementationAutoDiscovery (worker , clazz , null , workers );
174
185
}
175
186
}
176
187
}
@@ -197,7 +208,7 @@ private void configureActivityBeansByTaskQueue(
197
208
}
198
209
199
210
configureActivityImplementationAutoDiscovery (
200
- worker , bean , beanName , targetClass , null );
211
+ worker , bean , beanName , targetClass , null , workers );
201
212
}
202
213
}
203
214
});
@@ -218,7 +229,7 @@ private void configureWorkflowImplementationsByWorkerName(
218
229
+ clazz );
219
230
}
220
231
221
- configureWorkflowImplementationAutoDiscovery (worker , clazz , workerName );
232
+ configureWorkflowImplementationAutoDiscovery (worker , clazz , workerName , workers );
222
233
}
223
234
}
224
235
}
@@ -241,7 +252,7 @@ private void configureActivityBeansByWorkerName(
241
252
}
242
253
243
254
configureActivityImplementationAutoDiscovery (
244
- worker , bean , beanName , targetClass , workerName );
255
+ worker , bean , beanName , targetClass , workerName , workers );
245
256
}
246
257
}
247
258
});
@@ -303,14 +314,21 @@ private void createWorkerFromAnExplicitConfig(
303
314
AopUtils .getTargetClass (bean ),
304
315
taskQueue );
305
316
worker .registerActivitiesImplementations (bean );
317
+ addRegisteredActivityImpl (worker , beanName , bean .getClass ().getName ());
306
318
});
307
319
}
308
320
}
309
321
310
322
private void configureActivityImplementationAutoDiscovery (
311
- Worker worker , Object bean , String beanName , Class <?> targetClass , String byWorkerName ) {
323
+ Worker worker ,
324
+ Object bean ,
325
+ String beanName ,
326
+ Class <?> targetClass ,
327
+ String byWorkerName ,
328
+ Workers workers ) {
312
329
try {
313
330
worker .registerActivitiesImplementations (bean );
331
+ addRegisteredActivityImpl (worker , beanName , bean .getClass ().getName ());
314
332
if (log .isInfoEnabled ()) {
315
333
log .info (
316
334
"Registering auto-discovered activity bean '{}' of class {} on a worker {}with a task queue '{}'" ,
@@ -334,7 +352,7 @@ private void configureActivityImplementationAutoDiscovery(
334
352
}
335
353
336
354
private void configureWorkflowImplementationAutoDiscovery (
337
- Worker worker , Class <?> clazz , String byWorkerName ) {
355
+ Worker worker , Class <?> clazz , String byWorkerName , Workers workers ) {
338
356
try {
339
357
configureWorkflowImplementation (worker , clazz );
340
358
if (log .isInfoEnabled ()) {
@@ -378,6 +396,7 @@ private <T> void configureWorkflowImplementation(Worker worker, Class<?> clazz)
378
396
(Class <T >) workflowMethod .getWorkflowInterface (),
379
397
() -> (T ) beanFactory .createBean (clazz ),
380
398
workflowImplementationOptions );
399
+ addRegisteredWorkflowImpl (worker , workflowMethod .getWorkflowInterface ().getName ());
381
400
}
382
401
}
383
402
@@ -410,6 +429,94 @@ private Worker createNewWorker(
410
429
return worker ;
411
430
}
412
431
432
+ private void addRegisteredWorkflowImpl (Worker worker , String workflowClass ) {
433
+ if (!registeredInfo .containsKey (worker .getTaskQueue ())) {
434
+ registeredInfo .put (
435
+ worker .getTaskQueue (),
436
+ new RegisteredInfo ()
437
+ .addWorkflowInfo (new RegisteredWorkflowInfo ().addClassName (workflowClass )));
438
+ } else {
439
+ registeredInfo
440
+ .get (worker .getTaskQueue ())
441
+ .getRegisteredWorkflowInfo ()
442
+ .add (new RegisteredWorkflowInfo ().addClassName (workflowClass ));
443
+ }
444
+ }
445
+
446
+ private void addRegisteredActivityImpl (Worker worker , String beanName , String beanClass ) {
447
+ if (!registeredInfo .containsKey (worker .getTaskQueue ())) {
448
+ registeredInfo .put (
449
+ worker .getTaskQueue (),
450
+ new RegisteredInfo ()
451
+ .addActivityInfo (
452
+ new RegisteredActivityInfo ().addBeanName (beanName ).addClassName (beanClass )));
453
+ } else {
454
+ registeredInfo
455
+ .get (worker .getTaskQueue ())
456
+ .getRegisteredActivityInfo ()
457
+ .add (new RegisteredActivityInfo ().addBeanName (beanName ).addClassName (beanClass ));
458
+ }
459
+ }
460
+
461
+ public static class RegisteredInfo {
462
+ private final List <RegisteredActivityInfo > registeredActivityInfo = new ArrayList <>();
463
+ private final List <RegisteredWorkflowInfo > registeredWorkflowInfo = new ArrayList <>();
464
+
465
+ public RegisteredInfo addActivityInfo (RegisteredActivityInfo activityInfo ) {
466
+ registeredActivityInfo .add (activityInfo );
467
+ return this ;
468
+ }
469
+
470
+ public RegisteredInfo addWorkflowInfo (RegisteredWorkflowInfo workflowInfo ) {
471
+ registeredWorkflowInfo .add (workflowInfo );
472
+ return this ;
473
+ }
474
+
475
+ public List <RegisteredActivityInfo > getRegisteredActivityInfo () {
476
+ return registeredActivityInfo ;
477
+ }
478
+
479
+ public List <RegisteredWorkflowInfo > getRegisteredWorkflowInfo () {
480
+ return registeredWorkflowInfo ;
481
+ }
482
+ }
483
+
484
+ public static class RegisteredActivityInfo {
485
+ private String beanName ;
486
+ private String className ;
487
+
488
+ public RegisteredActivityInfo addClassName (String className ) {
489
+ this .className = className ;
490
+ return this ;
491
+ }
492
+
493
+ public RegisteredActivityInfo addBeanName (String beanName ) {
494
+ this .beanName = beanName ;
495
+ return this ;
496
+ }
497
+
498
+ public String getClassName () {
499
+ return className ;
500
+ }
501
+
502
+ public String getBeanName () {
503
+ return beanName ;
504
+ }
505
+ }
506
+
507
+ public static class RegisteredWorkflowInfo {
508
+ private String className ;
509
+
510
+ public RegisteredWorkflowInfo addClassName (String className ) {
511
+ this .className = className ;
512
+ return this ;
513
+ }
514
+
515
+ public String getClassName () {
516
+ return className ;
517
+ }
518
+ }
519
+
413
520
private static class Workers {
414
521
private final Map <String , Worker > workersByName = new HashMap <>();
415
522
private final Map <String , Worker > workersByTaskQueue = new HashMap <>();
0 commit comments