1717package group .rxcloud .capa .infrastructure .hook ;
1818
1919import group .rxcloud .capa .infrastructure .CapaClassLoader ;
20+ import io .vavr .Lazy ;
2021import org .slf4j .Logger ;
2122import org .slf4j .LoggerFactory ;
2223
@@ -30,15 +31,15 @@ public abstract class Mixer {
3031
3132 private static final Logger logger = LoggerFactory .getLogger (Mixer .class );
3233
33- private static ConfigurationHooks configurationHooks ;
34- private static TelemetryHooks telemetryHooks ;
34+ private static Lazy < ConfigurationHooks > configurationHooks ;
35+ private static Lazy < TelemetryHooks > telemetryHooks ;
3536
3637 static {
3738 try {
3839 MixerProvider mixerProvider = CapaClassLoader .loadInfrastructureClassObj ("mixer" , MixerProvider .class );
3940 if (mixerProvider != null ) {
40- registerConfigurationHooks (mixerProvider . provideConfigurationHooks ( ));
41- registerTelemetryHooks (mixerProvider . provideTelemetryHooks ( ));
41+ registerConfigurationHooks (Lazy . of ( mixerProvider :: provideConfigurationHooks ));
42+ registerTelemetryHooks (Lazy . of ( mixerProvider :: provideTelemetryHooks ));
4243 }
4344 } catch (Exception e ) {
4445 logger .info ("[CapaMixer] load empty mixer. expected error: " , e );
@@ -70,7 +71,7 @@ public interface MixerProvider {
7071 *
7172 * @param configurationHooks the configuration hooks
7273 */
73- private static void registerConfigurationHooks (ConfigurationHooks configurationHooks ) {
74+ private static void registerConfigurationHooks (Lazy < ConfigurationHooks > configurationHooks ) {
7475 Mixer .configurationHooks = configurationHooks ;
7576 }
7677
@@ -79,7 +80,7 @@ private static void registerConfigurationHooks(ConfigurationHooks configurationH
7980 *
8081 * @param telemetryHooks the telemetry hooks
8182 */
82- private static void registerTelemetryHooks (TelemetryHooks telemetryHooks ) {
83+ private static void registerTelemetryHooks (Lazy < TelemetryHooks > telemetryHooks ) {
8384 Mixer .telemetryHooks = telemetryHooks ;
8485 }
8586
@@ -90,7 +91,9 @@ private static void registerTelemetryHooks(TelemetryHooks telemetryHooks) {
9091 */
9192 @ Nullable
9293 public static ConfigurationHooks configurationHooks () {
93- return configurationHooks ;
94+ return configurationHooks != null
95+ ? configurationHooks .get ()
96+ : null ;
9497 }
9598
9699 /**
@@ -99,7 +102,7 @@ public static ConfigurationHooks configurationHooks() {
99102 * @return the configuration hooks
100103 */
101104 public static Optional <ConfigurationHooks > configurationHooksNullable () {
102- return Optional .ofNullable (configurationHooks );
105+ return Optional .ofNullable (configurationHooks . get () );
103106 }
104107
105108 /**
@@ -109,7 +112,9 @@ public static Optional<ConfigurationHooks> configurationHooksNullable() {
109112 */
110113 @ Nullable
111114 public static TelemetryHooks telemetryHooks () {
112- return telemetryHooks ;
115+ return telemetryHooks != null
116+ ? telemetryHooks .get ()
117+ : null ;
113118 }
114119
115120 /**
@@ -118,6 +123,6 @@ public static TelemetryHooks telemetryHooks() {
118123 * @return the telemetry hooks
119124 */
120125 public static Optional <TelemetryHooks > telemetryHooksNullable () {
121- return Optional .ofNullable (telemetryHooks );
126+ return Optional .ofNullable (telemetryHooks . get () );
122127 }
123128}
0 commit comments