public class Watch extends ConfigurationYamlImpl<YamlConfig>
Models the entrypoint to this module. At application startup, a single instance of Watch should be created
and subsequently used to (1) register configuration files to be watched, and (2) create configuration objects which
will encompass those files.
The singleton instance of Watch can be constructed in two ways, both of which require a configuration YAML
(see https://github.com/alanbuttars/commons-java/wiki/commons-config#commonsconfigyml.
java -Dcommons.config=/path/to/commons.config.yml -jar MyApplication.jarThen in your main class:
public class MyApplication {
public static void main(String[] args) {
EventBus eventBus = new EventBusSyncImpl();
Watch watch = Watch.config().withEventBus(eventBus);
}
}
public class MyApplication {
public static void main(String[] args) {
EventBus eventBus = new EventBusAsyncImpl();
Watch watch = Watch.config("/path/to/commons.config.yml").withEventBus(eventBus);
}
}
Once you have created your singleton Watch, you can use it to create Configuration objects. See
https://github.com/alanbuttars/commons-java/wiki/commons-config#configuration.
public class MyApplication {
private static ConfigurationPropertiesImpl database;
private static ConfigurationJsonImpl admin;
public static void main(String[] args) {
EventBus eventBus = new EventBusSyncImpl();
Watch watch = Watch.config().withEventBus(eventBus);
database = watch.properties("database");
admin = watch.json("admin").mappedTo(User.class);
}
}
| Modifier and Type | Method and Description |
|---|---|
static WatchStub |
config()
Creates an instance of this class, using the system property
commons.config. |
static WatchStub |
config(String yamlFilePath)
Creates an instance of this class, using the given file path.
|
WatchFileCustomImplStub |
custom(String sourceId)
Creates a custom configuration object.
|
ConfigurationDirectoryImpl |
directory(String sourceId)
Creates a configuration object from a directory.
|
protected ScheduledThreadPoolExecutor |
getExecutor() |
WatchFileJsonImplStub |
json(String sourceId)
Creates a configuration object from a JSON file.
|
ConfigurationPropertiesImpl |
properties(String sourceId)
Creates a configuration object from a properties file.
|
protected void |
reload(File configFile) |
WatchFileXmlImplStub |
xml(String sourceId)
Creates a configuration object from a XML file.
|
WatchFileYamlImplStub |
yaml(String sourceId)
Creates a configuration object from a YAML file.
|
loadgetEventBus, getSourceId, getValue, init, onFileEvent, onFileEventMatch, whenConfigFileCreated, whenConfigFileDeleted, whenConfigFileUpdatedprotected static final String SOURCE_ID
public static WatchStub config()
commons.config.IllegalArgumentException - If the system property points to an invalid filepublic static WatchStub config(String yamlFilePath)
yamlFilePath - Non-null file path of the configuration YAMLIllegalArgumentException - If the file path points to an invalid filepublic WatchFileJsonImplStub json(String sourceId)
sourceId - Non-null source ID from a JSON file entry in the master configuration YAMLpublic ConfigurationPropertiesImpl properties(String sourceId) throws IOException
sourceId - Non-null source ID from a properties file entry in the master configuration YAMLIOException - On I/O parsing the properties filepublic WatchFileXmlImplStub xml(String sourceId)
sourceId - Non-null source ID from a XML file entry in the master configuration YAMLpublic WatchFileYamlImplStub yaml(String sourceId)
sourceId - Non-null source ID from a YAML file entry in the master configuration YAMLpublic ConfigurationDirectoryImpl directory(String sourceId) throws IOException
sourceId - Non-null source ID from a directory file entry in the master configuration YAMLIOException - On I/O parsing the directorypublic WatchFileCustomImplStub custom(String sourceId)
sourceId - Non-null source ID from a file entry in the master configuration YAMLprotected void reload(File configFile) throws IOException
reload in class ConfigurationAbstractImpl<YamlConfig>IOExceptionprotected ScheduledThreadPoolExecutor getExecutor()
Copyright © 2016–2017. All rights reserved.