Skip to content

Commit

Permalink
[eclipse#414] Revert ChangeSupport enum changes
Browse files Browse the repository at this point in the history
Revert back to a simple ChangeSupport enum.
Add to the ConfigSource javadoc that a ConfigSource belongs to a single
Config.

Signed-off-by: Jeff Mesnil <[email protected]>
  • Loading branch information
jmesnil committed Aug 2, 2019
1 parent 1519484 commit cb0169b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
*******************************************************************************/
package org.eclipse.microprofile.config.spi;

import java.io.Closeable;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -71,9 +69,10 @@
* <p>Adding a dynamic amount of custom config sources can be done programmatically via
* {@link org.eclipse.microprofile.config.spi.ConfigSourceProvider}.
*
* <p>If a ConfigSource implements the {@link AutoCloseable} interface
* then the {@link AutoCloseable#close()} method will be called when
* the underlying {@link org.eclipse.microprofile.config.Config} is being released.
* <p>A ConfigSource must belong to a single {@link org.eclipse.microprofile.config.Config}.
* If a ConfigSource implements the {@link AutoCloseable} interface
* then the {@link AutoCloseable#close()} method will be called when
* the underlying {@code Config} is being released.
*
* @author <a href="mailto:[email protected]">Mark Struberg</a>
* @author <a href="mailto:[email protected]">Gerhard Petracek</a>
Expand Down Expand Up @@ -176,44 +175,35 @@ default int getOrdinal() {
* @see ChangeSupport
*/
default ChangeSupport onAttributeChange(Consumer<Set<String>> callback) {
// do nothing by default. Just for compat with older ConfigSources.
// do nothing by default. Just for compatibility with older ConfigSources.
// return unsupported to tell config that it must re-query this source every time
return () -> ChangeSupport.Type.UNSUPPORTED;
return ChangeSupport.UNSUPPORTED;
}

/**
* What kind of change support this config source has.
* <p>
* {@link org.eclipse.microprofile.config.Config} implementations may use this information for internal optimizations.
*/
interface ChangeSupport extends Closeable, Serializable {

enum Type {
/**
* Config change is supported, this config source will invoke the callback provided by
* {@link ConfigSource#onAttributeChange(Consumer)}.
* <p>
* Example: File based config source that watches the file for changes
*/
SUPPORTED,
/**
* Config change is not supported. Configuration values can change, though this change is not reported back.
* <p>
* Example: LDAP based config source
*/
UNSUPPORTED,
/**
* Configuration values cannot change for the lifetime of this {@link ConfigSource}.
* <p>
* Example: Environment variables config source, classpath resource config source
*/
IMMUTABLE
}

Type getType();

@Override
default void close() {
}
enum ChangeSupport {
/**
* Config change is supported, this config source will invoke the callback provided by
* {@link ConfigSource#onAttributeChange(Consumer)}.
* <p>
* Example: File based config source that watches the file for changes
*/
SUPPORTED,
/**
* Config change is not supported. Configuration values can change, though this change is not reported back.
* <p>
* Example: LDAP based config source
*/
UNSUPPORTED,
/**
* Configuration values cannot change for the lifetime of this {@link ConfigSource}.
* <p>
* Example: Environment variables config source, classpath resource config source
*/
IMMUTABLE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void testOnAttributeChange() {
String key = "tck.config.test.onattributechange.key";
ConfigurableConfigSource.configure(config, key, "firstvalue");

ConfigAccessor<String> val = config.access(key, String.class).cacheFor(Duration.ofMillis(30)).build();
ConfigAccessor<String> val = config.access(key, String.class).cacheFor(Duration.ofMinutes(30)).build();
Assert.assertEquals(val.getValue(), "firstvalue");

// immediately change the value on the ConfigurableConfigSource that will notify the Config of the change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getName() {
@Override
public ConfigSource.ChangeSupport onAttributeChange(Consumer<Set<String>> reportAttributeChange) {
this.reportAttributeChange = reportAttributeChange;
return () -> ChangeSupport.Type.SUPPORTED;
return ChangeSupport.SUPPORTED;
}

public static void configure(Config cfg, String propertyName, String value) {
Expand Down

0 comments on commit cb0169b

Please sign in to comment.