Listeners

Configuration change events can be listened for using the following methods:

The {@link oaj.config.event.ConfigEventListener} interface consists of the following method:

The {@link oaj.config.event.ConfigEvent} class provides access to all the information about the updated entry:

The listener method is triggered:

In both cases, the listener is triggered after the changes have been committed.

final Config c = Config.create("MyConfig.cfg").build(); // Add a listener for changes to MySection/key1 c.addListener( new ConfigEventListener() { @Override public void onConfigChange(ConfigEvents) { for (ConfigEvent event : events) { if (event.getType() == SET_ENTRY) { String section = event.getSection(); String key = event.getKey(); if (section.equals("MySection") && key.equals("key1")) { // Get the new value from the event. String newVal = event.getValue(); // Or get the new value from the config (since the change has already been committed). newVal = c.getString("MySection/key1"); } } } } } )