@ConfigurableContext public class ConfigFileStore extends ConfigStore
Points to a file system directory containing configuration files.
Modifier and Type | Field and Description |
---|---|
static ConfigFileStore |
DEFAULT
Default file store, all default values.
|
static String |
FILESTORE_charset
Configuration property: Charset.
|
static String |
FILESTORE_directory
Configuration property: Local file system directory.
|
static String |
FILESTORE_extensions
Configuration property: File extensions.
|
static String |
FILESTORE_updateOnWrite
Configuration property: Update-on-write.
|
static String |
FILESTORE_useWatcher
Configuration property: Use watcher.
|
static String |
FILESTORE_watcherSensitivity
Configuration property: Watcher sensitivity.
|
Modifier | Constructor and Description |
---|---|
protected |
ConfigFileStore(PropertyStore ps)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
ConfigFileStoreBuilder |
builder()
Creates a builder from this context object.
|
void |
close() |
static ConfigFileStoreBuilder |
create()
Create a new builder for this object.
|
boolean |
exists(String name)
Checks whether the configuration with the specified name exists in this store.
|
protected void |
onFileEvent(WatchEvent<Path> e)
Gets called when the watcher service on this store is triggered with a file system change.
|
String |
read(String name)
Returns the contents of the configuration file.
|
protected String |
resolveName(String name)
Subclasses can override this method to convert config names to internal forms.
|
ObjectMap |
toMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
ConfigFileStore |
update(String name,
String newContents)
Called when the physical contents of a config file have changed.
|
String |
write(String name,
String expectedContents,
String newContents)
Saves the contents of the configuration file if the underlying storage hasn't been modified.
|
createDefaultSessionArgs, createSession, getMap, register, unregister, update
createSession, equals, getArrayProperty, getArrayProperty, getBooleanProperty, getCdlProperty, getClassArrayProperty, getClassArrayProperty, getClassArrayProperty, getClassListProperty, getClassListProperty, getClassMapProperty, getClassMapProperty, getClassProperty, getClassSetProperty, getClassSetProperty, getInstanceArrayProperty, getInstanceArrayProperty, getInstanceArrayProperty, getInstanceProperty, getInstanceProperty, getInstanceProperty, getIntegerProperty, getListProperty, getListProperty, getLongProperty, getMapProperty, getProperty, getProperty, getPropertyKeys, getPropertyStore, getSetProperty, getSetProperty, getStringProperty, getStringPropertyWithNone, hashCode, identityCode, toString
public static final String FILESTORE_directory
Identifies the path of the directory containing the configuration files.
public static final String FILESTORE_charset
Charset
Charset.defaultCharset()
Identifies the charset of external files.
public static final String FILESTORE_useWatcher
Use a file system watcher for file system changes.
close()
on this object closes the watcher.
public static final String FILESTORE_watcherSensitivity
WatcherSensitivity
WatcherSensitivity.MEDIUM
Determines how frequently the file system is polled for updates.
public static final String FILESTORE_updateOnWrite
When enabled, the update(String, String)
method will be called immediately following
calls to write(String, String, String)
when the contents are changing.
This allows for more immediate responses to configuration changes on file systems that use
polling watchers.
This may cause double-triggering of ConfigStoreListeners
.
public static final String FILESTORE_extensions
Defines what file extensions to search for when the config name does not have an extension.
public static final ConfigFileStore DEFAULT
protected ConfigFileStore(PropertyStore ps)
ps
- The settings for this content store.public static ConfigFileStoreBuilder create()
public ConfigFileStoreBuilder builder()
Context
Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
public String read(String name) throws IOException
ConfigStore
read
in class ConfigStore
name
- The config file name.IOException
- Thrown by underlying stream.public String write(String name, String expectedContents, String newContents) throws IOException
ConfigStore
write
in class ConfigStore
name
- The config file name.expectedContents
- The expected contents of the file.newContents
- The new contents.IOException
- Thrown by underlying stream.public boolean exists(String name)
ConfigStore
exists
in class ConfigStore
name
- The config name.protected String resolveName(String name)
ConfigStore
For example, the ConfigFileStore
class can take in both
resolveName
in class ConfigStore
name
- The name to resolve.public ConfigFileStore update(String name, String newContents)
ConfigStore
Triggers calls to ConfigStoreListener.onChange(String)
on all registered listeners.
update
in class ConfigStore
name
- The config name (e.g. the filename without the extension).newContents
- The new contents.public void close()
protected void onFileEvent(WatchEvent<Path> e) throws IOException
e
- The file system event.IOException
- Thrown by underlying stream.public ObjectMap toMap()
Context
toMap
in class ConfigStore
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.