Skip to content

Commit

Permalink
refs: eclipse#9 rename ConfigValue to ConfigAccessor
Browse files Browse the repository at this point in the history
as discussed in the EG meeting

Signed-off-by: Mark Struberg <[email protected]>
  • Loading branch information
struberg committed May 17, 2018
1 parent 81e4255 commit 2021eab
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
14 changes: 7 additions & 7 deletions api/src/main/java/javax/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* </pre>
*
* <p>For accessing a coniguration in a dynamic way you can also use {@link #access(String)}.
* This method returns a builder-style {@link ConfigValue} instance for the given key.
* This method returns a builder-style {@link ConfigAccessor} instance for the given key.
* You can further specify a Type of the underlying configuration, a cache time, lookup paths and
* many more.
*
Expand Down Expand Up @@ -128,16 +128,16 @@ public interface Config {
<T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType);

/**
* Create a {@link ConfigValue} to access the underlying configuration.
* Create a {@link ConfigAccessor} to access the underlying configuration.
*
* @param propertyName the property key
* @return a {@code ConfigValue} to access the given propertyName
* @return a {@code ConfigAccessor} to access the given propertyName
*/
ConfigValue<String> access(String propertyName);
ConfigAccessor<String> access(String propertyName);

/**
* <p>This method can be used to access multiple
* {@link ConfigValue} which must be consistent.
* {@link ConfigAccessor} which must be consistent.
* The returned {@link ConfigSnapshot} is an immutable object which contains all the
* resolved values at the time of calling this method.
*
Expand Down Expand Up @@ -172,11 +172,11 @@ public interface Config {
* They should be used as local variables inside a method.
* Values will not be reloaded for an open {@link ConfigSnapshot}.
*
* @param configValues the list of {@link ConfigValue} to be accessed in an atomic way
* @param configValues the list of {@link ConfigAccessor} to be accessed in an atomic way
*
* @return a new {@link ConfigSnapshot} which holds the resolved values of all the {@code configValues}.
*/
ConfigSnapshot snapshotFor(ConfigValue<?>... configValues);
ConfigSnapshot snapshotFor(ConfigAccessor<?>... configValues);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @author <a href="mailto:[email protected]">Mark Struberg</a>
* @author <a href="mailto:[email protected]">Gerhard Petracek</a>
*/
public interface ConfigValue<T> {
public interface ConfigAccessor<T> {

/**
* Sets the type of the configuration entry to the given class and returns this builder.
Expand All @@ -66,7 +66,7 @@ public interface ConfigValue<T> {
* @param <N> The target type
* @return This builder as a typed ConfigValue
*/
<N> ConfigValue<N> as(Class<N> clazz);
<N> ConfigAccessor<N> as(Class<N> clazz);

/**
* Declare the ConfigValue to return a List of the given Type.
Expand All @@ -77,38 +77,38 @@ public interface ConfigValue<T> {
*
* @return a ConfigValue for a list of configured comma separated values
*/
ConfigValue<List<T>> asList();
ConfigAccessor<List<T>> asList();

/**
* Declare the ConfigValue to return a Set of the given Type.
* The notation and escaping rules are the same like explained in {@link #asList()}
*
* @return a ConfigValue for a list of configured comma separated values
*/
ConfigValue<Set<T>> asSet();
ConfigAccessor<Set<T>> asSet();

/**
* Defines a {@link Converter} to be used instead of the default Converter resolving logic.
*
* @param converter The converter for the target type
* @return This builder as a typed ConfigValue
*/
ConfigValue<T> useConverter(Converter<T> converter);
ConfigAccessor<T> useConverter(Converter<T> converter);

/**
* Sets the default value to use in case the resolution returns null.
* @param value the default value
* @return This builder
*/
ConfigValue<T> withDefault(T value);
ConfigAccessor<T> withDefault(T value);

/**
* Sets the default value to use in case the resolution returns null. Converts the given String to the type of
* this resolver using the same method as used for the configuration entries.
* @param value string value to be converted and used as default
* @return This builder
*/
ConfigValue<T> withStringDefault(String value);
ConfigAccessor<T> withStringDefault(String value);

/**
* Specify that a resolved value will get cached for a certain maximum amount of time.
Expand All @@ -124,7 +124,7 @@ public interface ConfigValue<T> {
* @param timeUnit the TimeUnit for the value
* @return This builder
*/
ConfigValue<T> cacheFor(long value, TimeUnit timeUnit);
ConfigAccessor<T> cacheFor(long value, TimeUnit timeUnit);

/**
* Whether to evaluate variables in configured values.
Expand All @@ -139,7 +139,7 @@ public interface ConfigValue<T> {
* @param evaluateVariables whether to evaluate variables in values or not
* @return This builder
*/
ConfigValue<T> evaluateVariables(boolean evaluateVariables);
ConfigAccessor<T> evaluateVariables(boolean evaluateVariables);

/**
* Appends the resolved value of the given property to the key of this builder.
Expand Down Expand Up @@ -169,7 +169,7 @@ public interface ConfigValue<T> {
*
* @return This builder
*/
ConfigValue<T> withLookupChain(String... postfixNames);
ConfigAccessor<T> withLookupChain(String... postfixNames);

/**
* Returns the converted resolved filtered value.
Expand All @@ -184,11 +184,11 @@ public interface ConfigValue<T> {
/**
* Returns the value from a previously taken {@link ConfigSnapshot}.
*
* @param configSnapshot previously taken via {@link Config#snapshotFor(ConfigValue[])}
* @param configSnapshot previously taken via {@link Config#snapshotFor(ConfigAccessor[])}
* @return the resolved Value
* @see Config#snapshotFor(ConfigValue[])
* @see Config#snapshotFor(ConfigAccessor[])
* @throws IllegalArgumentException if the {@link ConfigSnapshot} hasn't been resolved
* for this {@link ConfigValue}
* for this {@link ConfigAccessor}
*/
T getValue(ConfigSnapshot configSnapshot);

Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/javax/config/ConfigSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
package javax.config;

/**
* A value holder for TypedResolver values which all got resolved in a guaranteed atomic way.
* A value holder for ConfigAccessor values which all got resolved in a guaranteed atomic way.
*
* @see Config#snapshotFor(ConfigValue[])
* @see ConfigValue#getValue(ConfigSnapshot)
* @see Config#snapshotFor(ConfigAccessor[])
* @see ConfigAccessor#getValue(ConfigSnapshot)
*
* @author <a href="mailto:[email protected]">Mark Struberg</a>
* @author Manfred Huber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
// Contributors:
// Mark Struberg

[[configvalue]]
== ConfigValue
[[configaccessor]]
== ConfigAccessor


The `ConfigValue` API is intended for typed configuration values and precise control over resolution.

=== ConfigValue Usage
=== ConfigAccessor Usage

The simplest usage of the API is resolution of a String property, equivalent to a call to `Config.getValue(propertyKey, String.class)`.
This can also be handled via `ConfigValue` as shown in the following example:

.Simple example of ConfigValue
[source,java]
-----------------------------------------------------------------
String userName = Config.access("user.name").getValue();
String userName = config.access("user.name").getValue();
-----------------------------------------------------------------


Expand All @@ -49,11 +49,11 @@ resolution sequence>> should be taken into account. When set to true, the sequen
* `withDefault(T value)` -- sets the default value, used in case the resolution returns `null`
* `getValue()` -- terminates the builder and returns the resolved value with the appropriate type

.A more complete example of TypedResolver
.A more complete example of ConfigAccessor
[source,java]
-----------------------------------------------------------------
Integer dbPort = ConfigResolver
.resolve("db.port")
Integer dbPort = config
.access("db.port")
.as(Integer.class)
.withProjectStage(true)
.parameterizedBy("db.vendor")
Expand Down
2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/javaconfig-spec.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ include::configsources.asciidoc[]

include::converters.asciidoc[]

include::configvalues.asciidoc[]
include::configaccessor.asciidoc[]

18 changes: 9 additions & 9 deletions tck/src/main/java/org/eclipse/configjsr/ConfigValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.testng.annotations.Test;

import javax.config.Config;
import javax.config.ConfigValue;
import javax.config.ConfigAccessor;
import javax.config.spi.ConfigSource;
import javax.inject.Inject;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void testGetValue() {

@Test
public void testGetValueWithDefault() {
ConfigValue<Integer> cfga = config.access("tck.config.test.javaconfig.configvalue.withdefault.notexisting")
ConfigAccessor<Integer> cfga = config.access("tck.config.test.javaconfig.configvalue.withdefault.notexisting")
.as(Integer.class)
.withDefault(Integer.valueOf(1234));

Expand All @@ -77,7 +77,7 @@ public void testGetValueWithDefault() {

@Test
public void testGetValueWithStringDefault() {
ConfigValue<Integer> cfga = config.access("tck.config.test.javaconfig.configvalue.withdefault.notexisting")
ConfigAccessor<Integer> cfga = config.access("tck.config.test.javaconfig.configvalue.withdefault.notexisting")
.as(Integer.class)
.withStringDefault("1234");

Expand All @@ -96,7 +96,7 @@ public void testLookupChain() {
* 0 0 -> com.foo.myapp
*
*/
ConfigValue<String> cv = config.access("com.foo.myapp")
ConfigAccessor<String> cv = config.access("com.foo.myapp")
.withLookupChain("mycorp", "${javaconfig.projectStage}");

Assert.assertFalse(cv.getOptionalValue().isPresent());
Expand Down Expand Up @@ -192,7 +192,7 @@ public void testBooleanConverter() {
public void testCacheFor() throws Exception {
String key = "tck.config.test.javaconfig.cachefor.key";
System.setProperty(key, "firstvalue");
ConfigValue<String> val = config.access(key).cacheFor(30, TimeUnit.MILLISECONDS);
ConfigAccessor<String> val = config.access(key).cacheFor(30, TimeUnit.MILLISECONDS);
Assert.assertEquals(val.getValue(), "firstvalue");

// immediately change the value
Expand All @@ -210,18 +210,18 @@ public void testCacheFor() throws Exception {
public void testDefaultValue() {
String key = "tck.config.test.javaconfig.somerandom.default.key";

ConfigValue<String> val = config.access(key);
ConfigAccessor<String> val = config.access(key);
Assert.assertNull(val.getDefaultValue());

ConfigValue<String> val2 = config.access(key).withDefault("abc");
ConfigAccessor<String> val2 = config.access(key).withDefault("abc");
Assert.assertEquals(val2.getDefaultValue(), "abc");
Assert.assertEquals(val2.getValue(), "abc");

ConfigValue<Integer> vali = config.access(key).as(Integer.class).withDefault(123);
ConfigAccessor<Integer> vali = config.access(key).as(Integer.class).withDefault(123);
Assert.assertEquals(vali.getDefaultValue(), Integer.valueOf(123));
Assert.assertEquals(vali.getValue(), Integer.valueOf(123));

ConfigValue<Integer> vali2 = config.access(key).as(Integer.class).withStringDefault("123");
ConfigAccessor<Integer> vali2 = config.access(key).as(Integer.class).withStringDefault("123");
Assert.assertEquals(vali2.getDefaultValue(), Integer.valueOf(123));
Assert.assertEquals(vali2.getValue(), Integer.valueOf(123));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.concurrent.TimeUnit;

import javax.config.Config;
import javax.config.ConfigValue;
import javax.config.ConfigAccessor;
import javax.config.spi.ConfigSource;
import javax.inject.Inject;

Expand Down Expand Up @@ -74,7 +74,7 @@ public void testBgCount() throws Exception {

@Test
public void testValueInvalidationOnConfigChange() throws Exception {
ConfigValue<Integer> valCfg = config.access(DynamicChangeConfigSource.TEST_ATTRIBUTE)
ConfigAccessor<Integer> valCfg = config.access(DynamicChangeConfigSource.TEST_ATTRIBUTE)
.as(Integer.class)
.cacheFor(15, TimeUnit.MINUTES);

Expand Down

0 comments on commit 2021eab

Please sign in to comment.