@@ -128,27 +128,20 @@ public void close() {
128128 */
129129 @ Override
130130 protected <T > Mono <List <ConfigurationItem <T >>> doGet (String appId , String group , String label , List <String > keys , Map <String , String > metadata , TypeRef <T > type ) {
131- List <ConfigurationItem <T >> items = new ArrayList <>();
132131 if (CollectionUtils .isNullOrEmpty (keys )) {
133- LOGGER .warn ("[Capa.Config] keys is null or empty,appId:{}" , appId );
132+ LOGGER .warn ("[[type= Capa.Config] ] keys is null or empty,appId:{}" , appId );
134133 return Mono .error (new CapaException (CapaErrorContext .PARAMETER_ERROR , "keys is null or empty" ));
135134 }
136135
137136 String applicationName = String .format (APPCONFIG_NAME_FORMAT , appId , CapaFoundation .getEnv (FoundationType .TRIP ));
138137 String configurationName = keys .get (0 );
139138
140- GetConfigurationRequest request = GetConfigurationRequest .builder ()
141- .application (applicationName )
142- .clientId (UUID .randomUUID ().toString ())
143- .configuration (configurationName )
144- .environment (AwsCapaConfigurationProperties .AppConfigProperties .Settings .getConfigAwsAppConfigEnv ())
145- .build ();
139+ //init config and create subscribe polling
140+ initAndSubscribe (applicationName , configurationName , group , label , metadata , type );
146141
147- return Mono .fromCallable (() -> {
148- GetConfigurationResponse response = appConfigAsyncClient .getConfiguration (request ).get (REQUEST_TIMEOUT_IN_SECONDS , TimeUnit .SECONDS );
149- return convertToConfigurationList (response , configurationName , type );
150- })
151- .doOnError (e -> LOGGER .error ("[Capa.Config.getConfiguration] error occurs when getconfiguration, request:{}" , request , e ));
142+ //get current config from local
143+ ConfigurationItem <T > configurationItem = (ConfigurationItem <T >) getConfiguration (applicationName , configurationName ).getConfigurationItem ();
144+ return Mono .just (Lists .newArrayList (configurationItem ));
152145 }
153146
154147 @ Override
@@ -157,7 +150,7 @@ protected <T> Flux<SubscribeResp<T>> doSubscribe(String appId, String group, Str
157150 String applicationName = String .format (APPCONFIG_NAME_FORMAT , appId , CapaFoundation .getEnv (FoundationType .TRIP ));
158151 String configurationName = keys .get (0 );
159152
160- initSubscribe (applicationName , configurationName , group , label , metadata , type );
153+ initAndSubscribe (applicationName , configurationName , group , label , metadata , type );
161154 return doSub (applicationName , configurationName , group , label , metadata , type , appId );
162155 }
163156
@@ -175,7 +168,7 @@ protected <T> Flux<SubscribeResp<T>> doSubscribe(String appId, String group, Str
175168 private synchronized <T > Configuration <T > initConfig (String applicationName , String configurationName , String group , String label , Map <String , String > metadata , TypeRef <T > type ) {
176169 // double check whether has been initialized
177170 if (isInitialized (applicationName , configurationName )) {
178- LOGGER .info ("[Capa.Config.initConfig] config has been initialized before,applicationName:{},configurationName:{}" , applicationName , configurationName );
171+ LOGGER .info ("[[type= Capa.Config.initConfig] ] config has been initialized before,applicationName:{},configurationName:{}" , applicationName , configurationName );
179172 return Configuration .EMPTY ;
180173 }
181174 String version = getCurVersion (applicationName , configurationName );
@@ -188,28 +181,28 @@ private synchronized <T> Configuration<T> initConfig(String applicationName, Str
188181 .environment (AwsCapaConfigurationProperties .AppConfigProperties .Settings .getConfigAwsAppConfigEnv ())
189182 .build ();
190183
191- LOGGER .debug ("[Capa.Config.initConfig] call getconfiguration in init process,request:{}" , request );
184+ LOGGER .debug ("[[type= Capa.Config.initConfig] ] call getconfiguration in init process,request:{}" , request );
192185
193186 return Mono .fromCallable (() -> {
194187 GetConfigurationResponse response = appConfigAsyncClient .getConfiguration (request ).get (REQUEST_TIMEOUT_IN_SECONDS , TimeUnit .SECONDS );
195- LOGGER .debug ("[Capa.Config.initConfig] call getconfiguration in init process,response:{}" , response );
188+ LOGGER .debug ("[[type= Capa.Config.initConfig] ] call getconfiguration in init process,response:{}" , response );
196189 return response ;
197190 })
198- .doOnError (e -> LOGGER .error ("[initConfig] error occurs when getconfiguration in init process, request:{}" , request , e ))
191+ .doOnError (e -> LOGGER .error ("[[type=Capa.Config. initConfig] ] error occurs when getconfiguration in init process, request:{}" , request , e ))
199192 .map (resp -> initConfigurationItem (applicationName , configurationName , type , resp .content (), resp .configurationVersion ()))
200193 .block ();
201194 }
202195
203- private <T > void initSubscribe (String applicationName , String configurationName , String group , String label , Map <String , String > metadata , TypeRef <T > type ) {
196+ private <T > void initAndSubscribe (String applicationName , String configurationName , String group , String label , Map <String , String > metadata , TypeRef <T > type ) {
204197 if (!isInitialized (applicationName , configurationName )) {
205198 initConfig (applicationName , configurationName , group , label , metadata , type );
206199 }
207200 if (!isSubscribed (applicationName , configurationName )) {
208- createSubscribe (applicationName , configurationName , type );
201+ createSubscribePolling (applicationName , configurationName , type );
209202 }
210203 }
211204
212- private synchronized <T > void createSubscribe (String applicationName , String configurationName , TypeRef <T > type ) {
205+ private synchronized <T > void createSubscribePolling (String applicationName , String configurationName , TypeRef <T > type ) {
213206 if (isSubscribed (applicationName , configurationName )) {
214207 return ;
215208 }
@@ -229,17 +222,17 @@ private synchronized <T> void createSubscribe(String applicationName, String con
229222 .clientConfigurationVersion (version )
230223 .environment (AwsCapaConfigurationProperties .AppConfigProperties .Settings .getConfigAwsAppConfigEnv ())
231224 .build ();
232- LOGGER .debug ("[Capa.Config.subscribePolling] subscribe polling task start,request:{}" , request );
225+ LOGGER .debug ("[[type= Capa.Config.subscribePolling] ] subscribe polling task start,request:{}" , request );
233226
234227 GetConfigurationResponse resp = null ;
235228 try {
236229 resp = appConfigAsyncClient .getConfiguration (request ).get (REQUEST_TIMEOUT_IN_SECONDS , TimeUnit .SECONDS );
237230 } catch (InterruptedException | ExecutionException | TimeoutException e ) {
238231 //catch error,log error and not trigger listeners
239- LOGGER .error ("[Capa.Config.subscribePolling] error occurs when getConfiguration in polling process,configurationName:{},version:{}" , request .configuration (), request .clientConfigurationVersion (), e );
232+ LOGGER .error ("[[type= Capa.Config.subscribePolling] ] error occurs when getConfiguration in polling process,configurationName:{},version:{}" , request .configuration (), request .clientConfigurationVersion (), e );
240233 }
241234
242- LOGGER .debug ("[Capa.Config.subscribePolling] subscribe polling task end,response:{}" , resp );
235+ LOGGER .debug ("[[type= Capa.Config.subscribePolling] ] subscribe polling task end,response:{}" , resp );
243236
244237 if (resp != null && !Objects .equals (resp .configurationVersion (), version )) {
245238 fluxSink .next (resp );
@@ -255,7 +248,7 @@ private synchronized <T> void createSubscribe(String applicationName, String con
255248 })
256249 .filter (resp -> resp != Configuration .EMPTY )
257250 .subscribe (resp -> {
258- LOGGER .info ("[Capa.Config.triggerListener] receive changes and trigger listeners,response:{}" , resp );
251+ LOGGER .info ("[[type= Capa.Config.triggerListener] ] receive changes and trigger listeners,response:{}" , resp );
259252 resp .triggers (resp .getConfigurationItem ());
260253 });
261254 }
@@ -268,7 +261,7 @@ private <T> Flux<SubscribeResp<T>> doSub(String applicationName, String configur
268261 return Flux
269262 .create (fluxSink -> {
270263 configuration .addListener (configurationItem -> {
271- LOGGER .info ("[Capa.Config.listenerOnChange] listener onChanges, configurationItem:{}" , configurationItem );
264+ LOGGER .info ("[[type= Capa.Config.listenerOnChange]] listener onChanges, configurationItem key :{}" , configurationItem . getKey () );
272265 fluxSink .next (configurationItem );
273266 });
274267 })
@@ -330,7 +323,7 @@ private <T> Configuration<T> updateConfigurationItem(String applicationName, Str
330323 configuration .setConfigurationItem (configurationItem );
331324
332325 configMap .put (configurationName , configuration );
333- LOGGER .info ("[Capa.Config.updateConfig] update config,key configurationName:{},value configuration:{}" , configurationName , configuration );
326+ LOGGER .info ("[[type= Capa.Config.updateConfig] ] update config,key configurationName:{},value configuration:{}" , configurationName , configuration );
334327 return configuration ;
335328 }
336329 }
@@ -355,11 +348,11 @@ private <T> Configuration<T> initConfigurationItem(String applicationName, Strin
355348
356349 configMap .put (configurationName , configuration );
357350
358- LOGGER .info ("[Capa.Config.initConfig] process initConfigurationItem,put key configurationName:{},value configuration:{}" , configurationName , configuration );
351+ LOGGER .info ("[[type= Capa.Config.initConfig] ] process initConfigurationItem,put key configurationName:{},value configuration:{}" , configurationName , configuration );
359352
360353 if (initApplication ) {
361354 versionMap .put (applicationName , configMap );
362- LOGGER .info ("[Capa.Config.initConfig] process initConfigurationItem,put key applicationName:{}" , applicationName );
355+ LOGGER .info ("[[type= Capa.Config.initConfig] ] process initConfigurationItem,put key applicationName:{}" , applicationName );
363356 }
364357 return configuration ;
365358 }
0 commit comments