Example usage for org.apache.commons.configuration2.builder ConfigurationBuilderEvent CONFIGURATION_REQUEST

List of usage examples for org.apache.commons.configuration2.builder ConfigurationBuilderEvent CONFIGURATION_REQUEST

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.builder ConfigurationBuilderEvent CONFIGURATION_REQUEST.

Prototype

EventType CONFIGURATION_REQUEST

To view the source code for org.apache.commons.configuration2.builder ConfigurationBuilderEvent CONFIGURATION_REQUEST.

Click Source Link

Document

The specific event type for configuration request events.

Usage

From source file:org.apache.nifi.lookup.configuration2.CommonsConfigurationLookupService.java

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    final String config = context.getProperty(CONFIGURATION_FILE).getValue();
    final FileBasedBuilderParameters params = new Parameters().fileBased().setFile(new File(config));
    this.builder = new ReloadingFileBasedConfigurationBuilder<>(resultClass).configure(params);
    builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST,
            new EventListener<ConfigurationBuilderEvent>() {
                @Override//from  ww  w  . j a  v a 2 s.c  o  m
                public void onEvent(ConfigurationBuilderEvent event) {
                    if (builder.getReloadingController().checkForReloading(null)) {
                        getLogger().debug("Reloading " + config);
                    }
                }
            });

    try {
        // Try getting configuration to see if there is any issue, for example wrong file format.
        // Then throw InitializationException to keep this service in 'Enabling' state.
        builder.getConfiguration();
    } catch (ConfigurationException e) {
        throw new InitializationException(e);
    }
}