44import io .scalecube .config .ConfigRegistrySettings ;
55import io .scalecube .config .StringConfigProperty ;
66import io .scalecube .config .source .ClassPathConfigSource ;
7+ import io .scalecube .config .source .SystemPropertiesConfigSource ;
78import java .nio .file .Path ;
89import java .util .function .Predicate ;
910
@@ -17,19 +18,41 @@ public class PredicateOrderingConfigExample {
1718 */
1819 public static void main (String [] args ) {
1920 Predicate <Path > propsPredicate = path -> path .toString ().endsWith (".props" );
21+ Predicate <Path > rootPredicate =
22+ propsPredicate .and (path -> path .toString ().contains ("config.props" ));
2023 Predicate <Path > firstPredicate = propsPredicate .and (path -> path .toString ().contains ("order1" ));
2124 Predicate <Path > secondPredicate =
2225 propsPredicate .and (path -> path .toString ().contains ("order2" ));
26+ Predicate <Path > customSysPredicate =
27+ propsPredicate .and (path -> path .toString ().contains ("customSys" ));
28+
29+ // Emulate scenario where sys.foo was also given from system properties
30+ // System.setProperty("sys.foo", "sys foo from java system properties");
2331
2432 ConfigRegistry configRegistry =
2533 ConfigRegistry .create (
2634 ConfigRegistrySettings .builder ()
35+ .addLastSource ("sysProps" , new SystemPropertiesConfigSource ())
36+ .addLastSource (
37+ "customSysProps" ,
38+ new SystemPropertiesConfigSource (new ClassPathConfigSource (customSysPredicate )))
2739 .addLastSource (
28- "classpath" , new ClassPathConfigSource (firstPredicate , secondPredicate ))
40+ "classpath" ,
41+ new ClassPathConfigSource (firstPredicate , secondPredicate , rootPredicate ))
2942 .build ());
3043
3144 StringConfigProperty orderedProp1 = configRegistry .stringProperty ("orderedProp1" );
45+ String foo = configRegistry .stringValue ("foo" , null );
46+ String bar = configRegistry .stringValue ("bar" , null );
47+ String sysFoo = configRegistry .stringValue ("sys.foo" , null );
3248
33- System .out .println ("### Matched by first predicate orderedProp1=" + orderedProp1 .value ().get ());
49+ System .out .println (
50+ "### Matched by first predicate: orderedProp1=" + orderedProp1 .value ().get ());
51+ System .out .println ("### Regardeless of predicates: foo=" + foo + ", bar=" + bar );
52+ System .out .println (
53+ "### Custom system property: sysFoo="
54+ + sysFoo
55+ + ", System.getProperty(sysFoo)="
56+ + System .getProperty ("sys.foo" ));
3457 }
3558}
0 commit comments