Example usage for org.apache.commons.configuration.event ConfigurationEvent getSource

List of usage examples for org.apache.commons.configuration.event ConfigurationEvent getSource

Introduction

In this page you can find the example usage for org.apache.commons.configuration.event ConfigurationEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:com.netflix.config.ExpandedConfigurationListenerAdapter.java

/**
 * {@inheritDoc}/* w w  w  .  j  av  a 2s .  c  o m*/
 * @see ConfigurationListener#configurationChanged(ConfigurationEvent)
 */
@SuppressWarnings("unchecked")
@Override
public void configurationChanged(final ConfigurationEvent event) {

    if (pauseListener) {
        return;
    }

    // Grab the event information. Some values may be null.
    final Object source = event.getSource();
    final String name = event.getPropertyName();
    final Object value = event.getPropertyValue();
    final boolean beforeUpdate = event.isBeforeUpdate();

    // Handle the different types.
    switch (event.getType()) {

    // Key identifies node where the Collection of nodes was added, or
    // null if it was at the root.
    case HierarchicalConfiguration.EVENT_ADD_NODES:
    case ConcurrentCompositeConfiguration.EVENT_CONFIGURATION_SOURCE_CHANGED:
        expandedListener.configSourceLoaded(source);
        break;

    // Key identifies the individual property that was added.
    case AbstractConfiguration.EVENT_ADD_PROPERTY:
        expandedListener.addProperty(source, name, value, beforeUpdate);
        break;

    // Entire configuration was cleared.
    case AbstractConfiguration.EVENT_CLEAR:
        expandedListener.clear(source, beforeUpdate);
        break;

    // Key identifies the single property that was cleared.
    case AbstractConfiguration.EVENT_CLEAR_PROPERTY:
        expandedListener.clearProperty(source, name, value, beforeUpdate);
        break;

    // Key identifies the nodes that were removed, along with all its
    // children. Value after update is the List of nodes that were
    // cleared. Before the update, the value is null.
    case HierarchicalConfiguration.EVENT_CLEAR_TREE:
        // Ignore this. We rewrote the clearTree() method below.
        break;

    // The current property set is invalid.
    case CombinedConfiguration.EVENT_COMBINED_INVALIDATE:
        //listener.configSourceLoaded(source);
        break;

    // Key identifies the property that was read.
    case AbstractConfiguration.EVENT_READ_PROPERTY:
        break;

    // Key identifies the property that was set.
    case AbstractConfiguration.EVENT_SET_PROPERTY:
        expandedListener.setProperty(source, name, value, beforeUpdate);
        break;

    default:
        break;
    }
}

From source file:com.netflix.config.ConcurrentMapConfigurationTest.java

@Test
public void testListeners() {
    ConcurrentMapConfiguration conf = new ConcurrentMapConfiguration();
    final AtomicReference<ConfigurationEvent> eventRef = new AtomicReference<ConfigurationEvent>();
    conf.addConfigurationListener(new ConfigurationListener() {
        @Override//from   w ww  . j  a  v  a 2 s  .  c om
        public void configurationChanged(ConfigurationEvent arg0) {
            eventRef.set(arg0);
        }

    });
    conf.addProperty("key", "1");
    assertEquals(1, conf.getInt("key"));
    ConfigurationEvent event = eventRef.get();
    assertEquals("key", event.getPropertyName());
    assertEquals("1", event.getPropertyValue());
    assertTrue(conf == event.getSource());
    assertEquals(AbstractConfiguration.EVENT_ADD_PROPERTY, event.getType());
    conf.setProperty("key", "2");
    event = eventRef.get();
    assertEquals("key", event.getPropertyName());
    assertEquals("2", event.getPropertyValue());
    assertTrue(conf == event.getSource());
    assertEquals(AbstractConfiguration.EVENT_SET_PROPERTY, event.getType());
    conf.clearProperty("key");
    event = eventRef.get();
    assertEquals("key", event.getPropertyName());
    assertNull(event.getPropertyValue());
    assertTrue(conf == event.getSource());
    assertEquals(AbstractConfiguration.EVENT_CLEAR_PROPERTY, event.getType());
    conf.clear();
    assertFalse(conf.getKeys().hasNext());
    event = eventRef.get();
    assertTrue(conf == event.getSource());
    assertEquals(AbstractConfiguration.EVENT_CLEAR, event.getType());
}

From source file:com.jkoolcloud.tnt4j.repository.FileTokenRepository.java

@Override
public void configurationChanged(ConfigurationEvent event) {
    if (event.isBeforeUpdate())
        return;//from   w  w w . j av  a  2  s  .c  om
    logger.log(OpLevel.DEBUG, "configurationChanged: type={0}, {1}:{2}", event.getType(),
            event.getPropertyName(), event.getPropertyValue());
    switch (event.getType()) {
    case AbstractConfiguration.EVENT_ADD_PROPERTY:
        repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_ADD_KEY,
                event.getPropertyName(), event.getPropertyValue(), null));
        break;
    case AbstractConfiguration.EVENT_SET_PROPERTY:
        repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_SET_KEY,
                event.getPropertyName(), event.getPropertyValue(), null));
        break;
    case AbstractConfiguration.EVENT_CLEAR_PROPERTY:
        repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(),
                TokenRepository.EVENT_CLEAR_KEY, event.getPropertyName(), event.getPropertyValue(), null));
        break;
    case AbstractConfiguration.EVENT_CLEAR:
        repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_CLEAR,
                event.getPropertyName(), event.getPropertyValue(), null));
        break;
    case AbstractFileConfiguration.EVENT_RELOAD:
        repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_RELOAD,
                event.getPropertyName(), event.getPropertyValue(), null));
        break;
    }
}