Skip to content

Commit

Permalink
refs: eclipse#9 add value change Consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
struberg committed Dec 28, 2017
1 parent 482f096 commit c7c98c0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions api/src/main/java/javax/config/spi/ConfigValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
package javax.config.spi;


import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

/**
* Accessor to a configured value.
Expand All @@ -44,12 +46,31 @@ public interface ConfigValue<T> {
* Sets the type of the configuration entry to the given class and returns this builder.
* The default type of a ConfigValue is {@code String}.
*
* <p>Usage:
* <pre>
* Integer timeout = config.access("some.timeout")
* .as(Integer.class)
* .getValue();
* </pre>
*
*
* @param clazz The target type
* @param <N> The target type
* @return This builder as a typed ConfigValue
*/
<N> ConfigValue<N> as(Class<N> clazz);

/**
* Declare the ConfigValue to return a List of the given Type.
* When getting value it will be split on each comma (',') character.
* If a comma is contained in the values it must get escaped with a preceding backslash (&quot;\,&quot;).
* Any backslash needs to get escaped via double-backslash (&quot;\\&quot;).
* Note that in property files this leads to &quot;\\\\&quot; as properties escape themselves.
*
* @return a ConfigValue for a list of configured comma separated values
*/
ConfigValue<List<T>> asList();

/**
* Sets the type of the configuration entry to the given class, sets the converter to the one given and
* returns this builder. If a converter is provided for one of the types supported by
Expand Down Expand Up @@ -110,11 +131,12 @@ public interface ConfigValue<T> {
ConfigValue<T> withLookupChain(String... postfixNames);

/**
* Whether to log picking up any value changes as INFO.
* A user can register a Consumer which gets notified whenever
* a config change got detected.
*
* @return This builder
*/
ConfigValue<T> logChanges(boolean logChanges);
ConfigValue<T> onChange(Consumer<T> changedValueConsumer);

/**
* Returns the converted resolved filtered value.
Expand Down

0 comments on commit c7c98c0

Please sign in to comment.