@@ -409,6 +409,17 @@ private void configureActivityImplementationAutoDiscovery(
409
409
String byWorkerName ,
410
410
Workers workers ) {
411
411
try {
412
+ if (registeredInfo .containsKey (worker .getTaskQueue ())
413
+ && registeredInfo .get (worker .getTaskQueue ()).isActivityRegistered (beanName )) {
414
+ if (log .isInfoEnabled ()) {
415
+ log .debug (
416
+ "Activity bean {} is already registered on a worker {} with a task queue '{}'" ,
417
+ beanName ,
418
+ byWorkerName != null ? "'" + byWorkerName + "' " : "" ,
419
+ worker .getTaskQueue ());
420
+ }
421
+ return ; // already registered
422
+ }
412
423
worker .registerActivitiesImplementations (bean );
413
424
POJOActivityImplMetadata activityImplMetadata =
414
425
POJOActivityImplMetadata .newInstance (AopUtils .getTargetClass (bean ));
@@ -446,6 +457,17 @@ private void configureNexusServiceImplementationAutoDiscovery(
446
457
String byWorkerName ,
447
458
Workers workers ) {
448
459
try {
460
+ if (registeredInfo .containsKey (worker .getTaskQueue ())
461
+ && registeredInfo .get (worker .getTaskQueue ()).isNexusServiceRegistered (beanName )) {
462
+ if (log .isInfoEnabled ()) {
463
+ log .debug (
464
+ "Nexus service bean {} is already registered on a worker {} with a task queue '{}'" ,
465
+ beanName ,
466
+ byWorkerName != null ? "'" + byWorkerName + "' " : "" ,
467
+ worker .getTaskQueue ());
468
+ }
469
+ return ; // already registered
470
+ }
449
471
worker .registerNexusServiceImplementation (bean );
450
472
addRegisteredNexusServiceImpl (
451
473
worker ,
@@ -480,10 +502,21 @@ private void configureNexusServiceImplementationAutoDiscovery(
480
502
private void configureWorkflowImplementationAutoDiscovery (
481
503
Worker worker , Class <?> clazz , String byWorkerName , Workers workers ) {
482
504
try {
505
+ if (registeredInfo .containsKey (worker .getTaskQueue ())
506
+ && registeredInfo .get (worker .getTaskQueue ()).isWorkflowRegistered (clazz )) {
507
+ if (log .isInfoEnabled ()) {
508
+ log .debug (
509
+ "Workflow class {} is already registered on a worker {} with a task queue '{}'" ,
510
+ clazz ,
511
+ byWorkerName != null ? "'" + byWorkerName + "' " : "" ,
512
+ worker .getTaskQueue ());
513
+ }
514
+ return ; // already registered
515
+ }
483
516
configureWorkflowImplementation (worker , clazz );
484
517
if (log .isInfoEnabled ()) {
485
518
log .info (
486
- "Registering auto-discovered workflow class {} on a worker {}with a task queue '{}'" ,
519
+ "Registering auto-discovered workflow class {} on a worker {} with a task queue '{}'" ,
487
520
clazz ,
488
521
byWorkerName != null ? "'" + byWorkerName + "' " : "" ,
489
522
worker .getTaskQueue ());
@@ -494,7 +527,7 @@ private void configureWorkflowImplementationAutoDiscovery(
494
527
}
495
528
if (log .isInfoEnabled ()) {
496
529
log .info (
497
- "Skip registering of auto-discovered workflow class {} on a worker {}with a task queue '{}' "
530
+ "Skipping registering of auto-discovered workflow class {} on a worker {} with a task queue '{}' "
498
531
+ "as workflow type '{}' is already registered on the worker" ,
499
532
clazz ,
500
533
byWorkerName != null ? "'" + byWorkerName + "' " : "" ,
@@ -605,7 +638,7 @@ private <T> void configureWorkflowImplementation(Worker worker, Class<?> clazz)
605
638
},
606
639
workflowImplementationOptions );
607
640
addRegisteredWorkflowImpl (
608
- worker , workflowMethod .getWorkflowInterface ().getName (), workflowMetadata );
641
+ worker , clazz , workflowMethod .getWorkflowInterface ().getName (), workflowMetadata );
609
642
} else {
610
643
for (POJOWorkflowMethodMetadata workflowMethod : workflowMetadata .getWorkflowMethods ()) {
611
644
if (deploymentOptions != null && deploymentOptions .isUsingVersioning ()) {
@@ -623,7 +656,7 @@ private <T> void configureWorkflowImplementation(Worker worker, Class<?> clazz)
623
656
() -> (T ) beanFactory .createBean (clazz ),
624
657
workflowImplementationOptions );
625
658
addRegisteredWorkflowImpl (
626
- worker , workflowMethod .getWorkflowInterface ().getName (), workflowMetadata );
659
+ worker , clazz , workflowMethod .getWorkflowInterface ().getName (), workflowMetadata );
627
660
}
628
661
}
629
662
}
@@ -658,97 +691,82 @@ private Worker createNewWorker(
658
691
}
659
692
660
693
private void addRegisteredWorkflowImpl (
661
- Worker worker , String workflowClass , POJOWorkflowImplMetadata metadata ) {
662
- if (!registeredInfo .containsKey (worker .getTaskQueue ())) {
663
- registeredInfo .put (
664
- worker .getTaskQueue (),
665
- new RegisteredInfo ()
666
- .addWorkflowInfo (
667
- new RegisteredWorkflowInfo ().addClassName (workflowClass ).addMetadata (metadata )));
668
- } else {
669
- registeredInfo
670
- .get (worker .getTaskQueue ())
671
- .getRegisteredWorkflowInfo ()
672
- .add (new RegisteredWorkflowInfo ().addClassName (workflowClass ).addMetadata (metadata ));
673
- }
694
+ Worker worker , Class <?> clazz , String workflowClass , POJOWorkflowImplMetadata metadata ) {
695
+ registeredInfo
696
+ .computeIfAbsent (worker .getTaskQueue (), (k ) -> new RegisteredInfo ())
697
+ .addWorkflowInfo (
698
+ new RegisteredWorkflowInfo ()
699
+ .addImplementationClass (clazz )
700
+ .addClassName (workflowClass )
701
+ .addMetadata (metadata ));
674
702
}
675
703
676
704
private void addRegisteredActivityImpl (
677
705
Worker worker , String beanName , String beanClass , POJOActivityImplMetadata metadata ) {
678
- if (!registeredInfo .containsKey (worker .getTaskQueue ())) {
679
- registeredInfo .put (
680
- worker .getTaskQueue (),
681
- new RegisteredInfo ()
682
- .addActivityInfo (
683
- new RegisteredActivityInfo ()
684
- .addBeanName (beanName )
685
- .addClassName (beanClass )
686
- .addMetadata (metadata )));
687
- } else {
688
- registeredInfo
689
- .get (worker .getTaskQueue ())
690
- .getRegisteredActivityInfo ()
691
- .add (
692
- new RegisteredActivityInfo ()
693
- .addBeanName (beanName )
694
- .addClassName (beanClass )
695
- .addMetadata (metadata ));
696
- }
706
+ registeredInfo
707
+ .computeIfAbsent (worker .getTaskQueue (), (k ) -> new RegisteredInfo ())
708
+ .addActivityInfo (
709
+ new RegisteredActivityInfo ()
710
+ .addBeanName (beanName )
711
+ .addClassName (beanClass )
712
+ .addMetadata (metadata ));
697
713
}
698
714
699
715
private void addRegisteredNexusServiceImpl (
700
716
Worker worker , String beanName , String beanClass , ServiceDefinition serviceDefinition ) {
701
- if (!registeredInfo .containsKey (worker .getTaskQueue ())) {
702
- registeredInfo .put (
703
- worker .getTaskQueue (),
704
- new RegisteredInfo ()
705
- .addNexusServiceInfo (
706
- new RegisteredNexusServiceInfo ()
707
- .addBeanName (beanName )
708
- .addClassName (beanClass )
709
- .addDefinition (serviceDefinition )));
710
- } else {
711
- registeredInfo
712
- .get (worker .getTaskQueue ())
713
- .getRegisteredNexusServiceInfos ()
714
- .add (
715
- new RegisteredNexusServiceInfo ()
716
- .addBeanName (beanName )
717
- .addClassName (beanClass )
718
- .addDefinition (serviceDefinition ));
719
- }
717
+ registeredInfo
718
+ .computeIfAbsent (worker .getTaskQueue (), (k ) -> new RegisteredInfo ())
719
+ .addNexusServiceInfo (
720
+ new RegisteredNexusServiceInfo ()
721
+ .addBeanName (beanName )
722
+ .addClassName (beanClass )
723
+ .addDefinition (serviceDefinition ));
720
724
}
721
725
722
726
public static class RegisteredInfo {
723
- private final List <RegisteredActivityInfo > registeredActivityInfo = new ArrayList <>();
724
- private final List <RegisteredWorkflowInfo > registeredWorkflowInfo = new ArrayList <>();
725
- private final List <RegisteredNexusServiceInfo > registeredNexusServiceInfos = new ArrayList <>();
727
+ private final HashMap <Class <?>, RegisteredWorkflowInfo > registeredWorkflowInfo =
728
+ new HashMap <>();
729
+ private final HashMap <String , RegisteredActivityInfo > registeredActivityInfo = new HashMap <>();
730
+ private final HashMap <String , RegisteredNexusServiceInfo > registeredNexusServiceInfos =
731
+ new HashMap <>();
726
732
727
733
public RegisteredInfo addActivityInfo (RegisteredActivityInfo activityInfo ) {
728
- registeredActivityInfo .add ( activityInfo );
734
+ registeredActivityInfo .put ( activityInfo . getBeanName (), activityInfo );
729
735
return this ;
730
736
}
731
737
732
738
public RegisteredInfo addNexusServiceInfo (RegisteredNexusServiceInfo nexusServiceInfo ) {
733
- registeredNexusServiceInfos .add ( nexusServiceInfo );
739
+ registeredNexusServiceInfos .put ( nexusServiceInfo . getBeanName (), nexusServiceInfo );
734
740
return this ;
735
741
}
736
742
737
743
public RegisteredInfo addWorkflowInfo (RegisteredWorkflowInfo workflowInfo ) {
738
- registeredWorkflowInfo .add ( workflowInfo );
744
+ registeredWorkflowInfo .put ( workflowInfo . getImplementationClass (), workflowInfo );
739
745
return this ;
740
746
}
741
747
748
+ public boolean isWorkflowRegistered (Class <?> workflowClass ) {
749
+ return registeredWorkflowInfo .containsKey (workflowClass );
750
+ }
751
+
752
+ public boolean isActivityRegistered (String beanName ) {
753
+ return registeredActivityInfo .containsKey (beanName );
754
+ }
755
+
756
+ public boolean isNexusServiceRegistered (String beanName ) {
757
+ return registeredNexusServiceInfos .containsKey (beanName );
758
+ }
759
+
742
760
public List <RegisteredActivityInfo > getRegisteredActivityInfo () {
743
- return registeredActivityInfo ;
761
+ return new ArrayList <>( registeredActivityInfo . values ()) ;
744
762
}
745
763
746
764
public List <RegisteredWorkflowInfo > getRegisteredWorkflowInfo () {
747
- return registeredWorkflowInfo ;
765
+ return new ArrayList <>( registeredWorkflowInfo . values ()) ;
748
766
}
749
767
750
768
public List <RegisteredNexusServiceInfo > getRegisteredNexusServiceInfos () {
751
- return registeredNexusServiceInfos ;
769
+ return new ArrayList <>( registeredNexusServiceInfos . values ()) ;
752
770
}
753
771
}
754
772
@@ -822,6 +840,7 @@ public ServiceDefinition getDefinition() {
822
840
823
841
@ Experimental
824
842
public static class RegisteredWorkflowInfo {
843
+ private Class <?> implementationClass ;
825
844
private String className ;
826
845
private POJOWorkflowImplMetadata metadata ;
827
846
@@ -830,6 +849,11 @@ public RegisteredWorkflowInfo addClassName(String className) {
830
849
return this ;
831
850
}
832
851
852
+ public RegisteredWorkflowInfo addImplementationClass (Class <?> implementationClass ) {
853
+ this .implementationClass = implementationClass ;
854
+ return this ;
855
+ }
856
+
833
857
public RegisteredWorkflowInfo addMetadata (POJOWorkflowImplMetadata metadata ) {
834
858
this .metadata = metadata ;
835
859
return this ;
@@ -842,6 +866,10 @@ public String getClassName() {
842
866
public POJOWorkflowImplMetadata getMetadata () {
843
867
return metadata ;
844
868
}
869
+
870
+ public Class <?> getImplementationClass () {
871
+ return implementationClass ;
872
+ }
845
873
}
846
874
847
875
private static class Workers {
0 commit comments