Skip to main content

Config Stores Basics

Configuration files are stored in entities called Stores.

The methods that need to be implemented on a store are:

ConfigStoreread(String)write(String,String,String)update(String,String)

Read is self-explanatory:

public String read(String name) {
// Return the contents of the specified configuration.
}

Write is slightly trickier:

public String write(String name, String oldContents, String newContents) {

// If the old contents match the current stored contents, the new contents will get stored,
// and the method returns null indicating success.

// If the old contents DO NOT match the current stored contents (i.e. it was modified in some way),
// the new contents are NOT stored, and the method returns the current stored contents.

// If the old contents are null, then just always write the new contents.
}

The update method is called whenever the stored file gets modified externally:

public String update(String name, String newContents) {
// Do something with the updated contents.
}

Two configuration stores are provided by default:

FileStoreMemoryStore

The store is defined on the Config object via the following setting:

Config.Builderstore(ConfigStore)
Example
// Create a config with in-memory storage.
Config config = Config.create("MyConfig.cfg").store(ConfigMemoryStore.DEFAULT).build();

The default store used is FileStore.DEFAULT which defines the execution directory as the file system directory to store and retrieve files.