-
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.
Merge pull request #147 from scalecube/feature/146/predicate-shortcuts
Feature/146/predicate shortcuts
- Loading branch information
Showing
13 changed files
with
296 additions
and
208 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
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
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
Oops, something went wrong.