-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished woith pattern predicatse utilities
- Loading branch information
Showing
5 changed files
with
81 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...-examples/src/main/java/io/scalecube/config/examples/PredicateShortcutsConfigExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.scalecube.config.examples; | ||
|
||
import io.scalecube.config.ConfigRegistry; | ||
import io.scalecube.config.ConfigRegistrySettings; | ||
import io.scalecube.config.StringConfigProperty; | ||
import io.scalecube.config.source.ClassPathConfigSource; | ||
import io.scalecube.config.source.SystemPropertiesConfigSource; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@SuppressWarnings("OptionalGetWithoutIsPresent") | ||
public class PredicateShortcutsConfigExample { | ||
|
||
/** | ||
* Main method for example of predicate ordering. | ||
* | ||
* @param args program arguments | ||
*/ | ||
public static void main(String[] args) { | ||
// Emulate scenario where sys.foo was also given from system properties | ||
// System.setProperty("sys.foo", "sys foo from java system properties"); | ||
|
||
String mask = ".*config\\.props"; | ||
|
||
ConfigRegistry configRegistry = | ||
ConfigRegistry.create( | ||
ConfigRegistrySettings.builder() | ||
.addLastSource("sysProps", new SystemPropertiesConfigSource()) | ||
.addLastSource( | ||
"customSysProps", | ||
new SystemPropertiesConfigSource( | ||
ClassPathConfigSource.createWithPattern( | ||
mask, Stream.of("customSys").collect(Collectors.toList())))) | ||
.addLastSource( | ||
"classpath", | ||
ClassPathConfigSource.createWithPattern( | ||
mask, Stream.of("order1", "order2").collect(Collectors.toList()))) | ||
.build()); | ||
|
||
StringConfigProperty orderedProp1 = configRegistry.stringProperty("orderedProp1"); | ||
String foo = configRegistry.stringProperty("foo").valueOrThrow(); | ||
String bar = configRegistry.stringProperty("bar").valueOrThrow(); | ||
String sysFoo = configRegistry.stringProperty("sys.foo").valueOrThrow(); | ||
|
||
System.out.println( | ||
"### Matched by first predicate: orderedProp1=" + orderedProp1.value().get()); | ||
System.out.println("### Regardeless of predicates: foo=" + foo + ", bar=" + bar); | ||
System.out.println( | ||
"### Custom system property: sysFoo=" | ||
+ sysFoo | ||
+ ", System.getProperty(sysFoo)=" | ||
+ System.getProperty("sys.foo")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters