-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor SPI * only static spi * Revert log changes * Move all the ServiceLoader use into ConfigServiceLoader * Rename ConfigSPI to ConfigExtension * Remove unused META-INF/services/io.avaje.config.ConfigurationPlugin As this is replaced by the generated one for ConfigExtension * Move the initalisation of Parsers into ConfigServiceLoader so that it happens once. * Improve javadoc for ConfigServiceLoader --------- Co-authored-by: Rob Bygrave <robin.bygrave@gmail.com>
- Loading branch information
Showing
24 changed files
with
183 additions
and
82 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
16 changes: 11 additions & 5 deletions
16
avaje-aws-appconfig/src/main/java/io/avaje/config/appconfig/AppConfigPlugin.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
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
1 change: 0 additions & 1 deletion
1
avaje-aws-appconfig/src/main/resources/META-INF/services/io.avaje.config.ConfigurationSource
This file was deleted.
Oops, something went wrong.
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
23 changes: 23 additions & 0 deletions
23
avaje-config/src/main/java/io/avaje/config/ConfigExtension.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,23 @@ | ||
package io.avaje.config; | ||
|
||
import io.avaje.spi.Service; | ||
|
||
/** | ||
* Super interface for all extensions to avaje-config which are loaded via ServiceLoader. | ||
* <p> | ||
* Extend avaje-config by implementing one of the following extension interfaces below and | ||
* have it registered with {@link java.util.ServiceLoader} as a {@link ConfigExtension}. | ||
* | ||
* <h4>Extensions</h4> | ||
* <ul> | ||
* <li>{@link ConfigParser}</li> | ||
* <li>{@link ConfigurationLog}</li> | ||
* <li>{@link ConfigurationPlugin}</li> | ||
* <li>{@link ConfigurationSource}</li> | ||
* <li>{@link ResourceLoader}</li> | ||
* <li>{@link ModificationEventRunner}</li> | ||
* </ul> | ||
*/ | ||
@Service | ||
public interface ConfigExtension { | ||
} |
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
77 changes: 77 additions & 0 deletions
77
avaje-config/src/main/java/io/avaje/config/ConfigServiceLoader.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,77 @@ | ||
package io.avaje.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* Load all the avaje-config extensions via ServiceLoader using the single | ||
* common ConfigExtension interface. | ||
*/ | ||
final class ConfigServiceLoader { | ||
|
||
private static final ConfigServiceLoader INSTANCE = new ConfigServiceLoader(); | ||
|
||
static ConfigServiceLoader get() { | ||
return INSTANCE; | ||
} | ||
|
||
private final ConfigurationLog log; | ||
private final ResourceLoader resourceLoader; | ||
private final ModificationEventRunner eventRunner; | ||
private final List<ConfigurationSource> sources = new ArrayList<>(); | ||
private final List<ConfigurationPlugin> plugins = new ArrayList<>(); | ||
private final Parsers parsers; | ||
|
||
ConfigServiceLoader() { | ||
ModificationEventRunner _eventRunner = null; | ||
ConfigurationLog _log = null; | ||
ResourceLoader _resourceLoader = null; | ||
List<ConfigParser> otherParsers = new ArrayList<>(); | ||
|
||
for (var spi : ServiceLoader.load(ConfigExtension.class)) { | ||
if (spi instanceof ConfigurationSource) { | ||
sources.add((ConfigurationSource) spi); | ||
} else if (spi instanceof ConfigurationPlugin) { | ||
plugins.add((ConfigurationPlugin) spi); | ||
} else if (spi instanceof ConfigParser) { | ||
otherParsers.add((ConfigParser) spi); | ||
} else if (spi instanceof ConfigurationLog) { | ||
_log = (ConfigurationLog) spi; | ||
} else if (spi instanceof ResourceLoader) { | ||
_resourceLoader = (ResourceLoader) spi; | ||
} else if (spi instanceof ModificationEventRunner) { | ||
_eventRunner = (ModificationEventRunner) spi; | ||
} | ||
} | ||
|
||
this.log = _log == null ? new DefaultConfigurationLog() : _log; | ||
this.resourceLoader = _resourceLoader == null ? new DefaultResourceLoader() : _resourceLoader; | ||
this.eventRunner = _eventRunner == null ? new CoreConfiguration.ForegroundEventRunner() : _eventRunner; | ||
this.parsers = new Parsers(otherParsers); | ||
} | ||
|
||
Parsers parsers() { | ||
return parsers; | ||
} | ||
|
||
ConfigurationLog log() { | ||
return log; | ||
} | ||
|
||
ResourceLoader resourceLoader() { | ||
return resourceLoader; | ||
} | ||
|
||
ModificationEventRunner eventRunner() { | ||
return eventRunner; | ||
} | ||
|
||
List<ConfigurationSource> sources() { | ||
return sources; | ||
} | ||
|
||
List<ConfigurationPlugin> plugins() { | ||
return plugins; | ||
} | ||
} |
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
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
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.