@@ -53,7 +53,7 @@ public class ConfigurationFileUtils {
5353 private static final String lockFileSuffix = ".lock" ;
5454 private static final long maxTimeMillsToAcquireLock = TimeUnit .SECONDS .toMillis (20 );
5555 private static final long waitTimeMillsPerCheck = TimeUnit .MILLISECONDS .toMillis (100 );
56- private static Logger logger = LoggerFactory .getLogger (ConfigurationFileUtils .class );
56+ private static final Logger logger = LoggerFactory .getLogger (ConfigurationFileUtils .class );
5757 private static final String lineSeparator = "\n " ;
5858 private static final String license =
5959 new StringJoiner (lineSeparator )
@@ -74,11 +74,9 @@ public class ConfigurationFileUtils {
7474 .add ("# specific language governing permissions and limitations" )
7575 .add ("# under the License." )
7676 .toString ();
77- private static final String EFFECTIVE_MODE = "effectiveMode:" ;
78- private static final String DATATYPE = "Datatype:" ;
79- private static final String EFFECTIVE_MODE_HOT_RELOAD = "hot_reload" ;
80- private static final String EFFECTIVE_MODE_RESTART = "restart" ;
81- private static final String EFFECTIVE_MODE_FIRST_START = "first_start" ;
77+ private static final String EFFECTIVE_MODE_PREFIX = "effectiveMode:" ;
78+ private static final String EFFECTIVE_NODE_TYPE_PREFIX = "effectiveNodeType:" ;
79+ private static final String DATATYPE_PREFIX = "Datatype:" ;
8280 private static Map <String , DefaultConfigurationItem > configuration2DefaultValue ;
8381
8482 // This is a temporary implementations
@@ -113,9 +111,19 @@ public class ConfigurationFileUtils {
113111
114112 private static final Map <String , String > lastAppliedProperties = new HashMap <>();
115113
116- public static void updateLastAppliedProperties (TrimProperties properties ) {
114+ public static void updateLastAppliedProperties (
115+ TrimProperties properties , boolean isHotReloading ) throws IOException {
116+ loadConfigurationDefaultValueFromTemplate ();
117117 for (Map .Entry <Object , Object > entry : properties .entrySet ()) {
118118 String key = entry .getKey ().toString ();
119+ DefaultConfigurationItem defaultConfigurationItem = configuration2DefaultValue .get (key );
120+ if (defaultConfigurationItem == null ) {
121+ continue ;
122+ }
123+ if (isHotReloading
124+ && defaultConfigurationItem .effectiveMode != EffectiveModeType .HOT_RELOAD ) {
125+ continue ;
126+ }
119127 String value = entry .getValue () == null ? null : entry .getValue ().toString ();
120128 lastAppliedProperties .put (key , value );
121129 }
@@ -373,33 +381,37 @@ public static Map<String, DefaultConfigurationItem> getConfigurationItemsFromTem
373381 .getResourceAsStream (CommonConfig .SYSTEM_CONFIG_TEMPLATE_NAME );
374382 InputStreamReader isr = new InputStreamReader (inputStream );
375383 BufferedReader reader = new BufferedReader (isr )) {
376- String effectiveMode = null ;
377- String dataType = null ;
384+ EffectiveModeType effectiveMode = null ;
378385 StringBuilder description = new StringBuilder ();
379386 String line ;
380387 while ((line = reader .readLine ()) != null ) {
381388 line = line .trim ();
382389 if (line .isEmpty ()) {
383390 description = new StringBuilder ();
384- dataType = null ;
385391 effectiveMode = null ;
386392 continue ;
387393 }
388394 if (line .startsWith ("#" )) {
389395 String comment = line .substring (1 ).trim ();
390- if (description .length () > 0 ) {
391- if (comment .startsWith (EFFECTIVE_MODE )) {
392- effectiveMode = comment .substring (EFFECTIVE_MODE .length ()).trim ();
393- continue ;
394- } else if (comment .startsWith (DATATYPE )) {
395- dataType = comment .substring (DATATYPE .length ()).trim ();
396- continue ;
397- } else {
398- description .append (" " );
399- }
396+ if (comment .isEmpty ()) {
397+ continue ;
398+ }
399+ boolean needSeperateLine = false ;
400+ if (comment .startsWith (EFFECTIVE_MODE_PREFIX )) {
401+ effectiveMode =
402+ EffectiveModeType .getEffectiveMode (
403+ comment .substring (EFFECTIVE_MODE_PREFIX .length ()).trim ());
404+ needSeperateLine = true ;
405+ } else if (comment .startsWith (DATATYPE_PREFIX )) {
406+ needSeperateLine = true ;
407+ } else {
408+ description .append (" " );
400409 }
401410 if (withDesc ) {
402411 description .append (comment );
412+ if (needSeperateLine ) {
413+ description .append (lineSeparator );
414+ }
403415 }
404416 } else {
405417 int equalsIndex = line .indexOf ('=' );
@@ -408,11 +420,7 @@ public static Map<String, DefaultConfigurationItem> getConfigurationItemsFromTem
408420 items .put (
409421 key ,
410422 new DefaultConfigurationItem (
411- key ,
412- value ,
413- withDesc ? description .toString ().trim () : null ,
414- effectiveMode ,
415- dataType ));
423+ key , value , withDesc ? description .toString ().trim () : null , effectiveMode ));
416424 }
417425 }
418426 } catch (IOException e ) {
@@ -426,16 +434,33 @@ public static class DefaultConfigurationItem {
426434 public String name ;
427435 public String value ;
428436 public String description ;
429- public String effectiveMode ;
430- public String dataType ;
437+ public EffectiveModeType effectiveMode ;
431438
432439 public DefaultConfigurationItem (
433- String name , String value , String description , String effectiveMode , String dataType ) {
440+ String name , String value , String description , EffectiveModeType effectiveMode ) {
434441 this .name = name ;
435442 this .value = value ;
436443 this .description = description ;
437- this .effectiveMode = effectiveMode ;
438- this .dataType = dataType ;
444+ this .effectiveMode = effectiveMode == null ? EffectiveModeType .UNKNOWN : effectiveMode ;
445+ }
446+ }
447+
448+ public enum EffectiveModeType {
449+ HOT_RELOAD ,
450+ FIRST_START ,
451+ RESTART ,
452+ UNKNOWN ;
453+
454+ public static EffectiveModeType getEffectiveMode (String effectiveMode ) {
455+ if (HOT_RELOAD .name ().equalsIgnoreCase (effectiveMode )) {
456+ return HOT_RELOAD ;
457+ } else if (FIRST_START .name ().equalsIgnoreCase (effectiveMode )) {
458+ return FIRST_START ;
459+ } else if (RESTART .name ().equalsIgnoreCase (effectiveMode )) {
460+ return RESTART ;
461+ } else {
462+ return UNKNOWN ;
463+ }
439464 }
440465 }
441466}
0 commit comments