org.apache.commons.configuration.event.ConfigurationEvent Java Examples

The following examples show how to use org.apache.commons.configuration.event.ConfigurationEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PriorityPropertyManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public synchronized void configurationListener(ConfigurationEvent event) {
  if (event.isBeforeUpdate()) {
    return;
  }

  if (keyCache == null) {
    keyCache = new ConcurrentHashMapEx<>();
    updateCache(new Object(), priorityPropertySet);
    configObjectMap.forEach((k, v) -> updateCache(k, v));
  }

  if (event.getPropertyName() != null) {
    keyCache.forEach((k, v) -> v.getOrDefault(event.getPropertyName(), Collections.emptyList()).stream()
        .forEach(p -> p.updateFinalValue(false, k)));
    return;
  }

  // event like add configuration source, need to make a global refresh
  keyCache.forEach(
      (k, v) -> v.values().stream().flatMap(Collection::stream).forEach(
          p -> p.updateFinalValue(false, k)));
}
 
Example #2
Source File: DynamicRequestLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public DynamicRequestLimiter(DynamicDistributedLogConfiguration dynConf,
                             StatsLogger statsLogger,
                             Feature rateLimitDisabledFeature) {
    final StatsLogger limiterStatsLogger = statsLogger.scope("dynamic");
    this.dynConf = dynConf;
    this.rateLimitDisabledFeature = rateLimitDisabledFeature;
    this.listener = new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            // Note that this method may be called several times if several config options
            // are changed. The effect is harmless except that we create and discard more
            // objects than we need to.
            LOG.debug("Config changed callback invoked with event {} {} {} {}", new Object[] {
                    event.getPropertyName(), event.getPropertyValue(), event.getType(),
                    event.isBeforeUpdate()});
            if (!event.isBeforeUpdate()) {
                limiterStatsLogger.getCounter("config_changed").inc();
                LOG.debug("Rebuilding limiter");
                limiter = build();
            }
        }
    };
    LOG.debug("Registering config changed callback");
    dynConf.addConfigurationListener(listener);
}
 
Example #3
Source File: DynamicRequestLimiter.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
public DynamicRequestLimiter(DynamicDistributedLogConfiguration dynConf,
                             StatsLogger statsLogger, Feature rateLimitDisabledFeature) {
    final StatsLogger limiterStatsLogger = statsLogger.scope("dynamic");
    this.dynConf = dynConf;
    this.rateLimitDisabledFeature = rateLimitDisabledFeature;
    this.listener = new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            // Note that this method may be called several times if several config options
            // are changed. The effect is harmless except that we create and discard more
            // objects than we need to.
            LOG.debug("Config changed callback invoked with event {} {} {} {}", new Object[] {
                    event.getPropertyName(), event.getPropertyValue(), event.getType(),
                    event.isBeforeUpdate()});
            if (!event.isBeforeUpdate()) {
                limiterStatsLogger.getCounter("config_changed").inc();
                LOG.debug("Rebuilding limiter");
                limiter = build();
            }
        }
    };
    LOG.debug("Registering config changed callback");
    dynConf.addConfigurationListener(listener);
}
 
Example #4
Source File: ArchaiusPropertyResolver.java    From ribbon with Apache License 2.0 5 votes vote down vote up
private ArchaiusPropertyResolver() {
    this.config = ConfigurationManager.getConfigInstance();

    ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (!event.isBeforeUpdate()) {
                actions.forEach(ArchaiusPropertyResolver::invokeAction);
            }
        }
    });
}
 
Example #5
Source File: MetricsGraphiteConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
private void addConfigurationListener() {
    final MetricsGraphiteConfiguration springConfig = this;
    ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {

        @Override
        public synchronized void configurationChanged(ConfigurationEvent event) {
            if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY ||
                    event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY)) {
                return;
            }
            if (event.isBeforeUpdate()) {
                return;
            }
            String name = event.getPropertyName();
            if (!(name.equals(METRICS_GRAPHITE_ENABLED) ||
                    name.equals(METRICS_GRAPHITE_SERVER) ||
                    name.equals(METRICS_GRAPHITE_PORT) ||
                    name.equals(METRICS_GRAPHITE_FILTER) ||
                    name.equals(METRICS_GRAPHITE_PUBLISH_INTERVAL) ||
                    name.equals(METRICS_GRAPHITE_PUBLISH_INTERVAL_UNIT))) {
                return;
            }

            springConfig.enabled = name.equals(METRICS_GRAPHITE_ENABLED) ? Boolean.parseBoolean(event.getPropertyValue() + "") : springConfig.enabled;

            destroyReporterLoader();
            if (springConfig.enabled) {
                createReporterLoader();
            }

        }
    });
}
 
Example #6
Source File: MetricsCloudWatchConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
private void addConfigurationListener() {
    final MetricsCloudWatchConfiguration springConfig = this;
    ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {

        @Override
        public synchronized void configurationChanged(ConfigurationEvent event) {
            if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY ||
                    event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY)) {
                return;
            }
            if (event.isBeforeUpdate()) {
                return;
            }
            String name = event.getPropertyName();

            if (!(name.equals(METRICS_AWS_ENABLED) ||
                    name.equals(METRICS_AWS_FILTER) ||
                    name.equals(METRICS_AWS_PUBLISH_INTERVAL) ||
                    name.equals(METRICS_AWS_PUBLISH_INTERVAL_UNIT))) {
                return;
            }

            springConfig.enabled = name.equals(METRICS_AWS_ENABLED) ? Boolean.parseBoolean(event.getPropertyValue() + "") : springConfig.enabled;
            destroyReporter();
            if (springConfig.enabled) {
                createReporter();
            }

        }
    });
}
 
Example #7
Source File: TajoSystemMetrics.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void configurationChanged(ConfigurationEvent event) {
  if (!event.isBeforeUpdate()) {
    stopAndClearReporter();
    start();
  }
}
 
Example #8
Source File: TajoSystemMetrics.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void configurationChanged(ConfigurationEvent event) {
  if (!event.isBeforeUpdate()) {
    stopAndClearReporter();
    start();
  }
}
 
Example #9
Source File: ConfTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
public void configurationChanged(ConfigurationEvent event) {
  if (!event.isBeforeUpdate()) {
    // only display events after the modification was done
    System.out.println(name + " Received event!");
    System.out.println(name + " Type = " + event.getType());
    if (event.getPropertyName() != null) {
      System.out.println(name + " Property name = " + event.getPropertyName());
    }
    if (event.getPropertyValue() != null) {
      System.out.println(name + " Property value = " + event.getPropertyValue());
    }
  }
}
 
Example #10
Source File: MarkAllFoundAction.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Override
public void configurationChanged(ConfigurationEvent e) {
  if (e.getPropertyName() != null && e.getPropertyName().equalsIgnoreCase("gui.markColor")) {
    final Object propertyValue = e.getPropertyValue();
    if (propertyValue instanceof MarkerColors) {
      markerColors = (MarkerColors) propertyValue;
    } else if (propertyValue instanceof String) {
      String value = (String) propertyValue;
      markerColors = MarkerColors.fromString(value);
    }
  }
}
 
Example #11
Source File: ConsulController.java    From james with Apache License 2.0 5 votes vote down vote up
private void onInformationPointRemoved(ConfigurationEvent event, InformationPointService informationPointService) {
    String methodReference = readMethodReference(event);

    InformationPoint informationPoint = InformationPoint.builder().withMethodReference(methodReference).build();
    informationPointService.removeInformationPoint(informationPoint);
    LOG.trace(() -> "Information point " + informationPoint + " removed");
}
 
Example #12
Source File: ConsulController.java    From james with Apache License 2.0 5 votes vote down vote up
private void onInformationPointModified(ConfigurationEvent event, InformationPointService informationPointService) {
    String methodReference = readMethodReference(event);
    String informationPointDtoAsJsonString = (String) event.getPropertyValue();

    Optional<InformationPoint> informationPoint =
            InformationPointDTOParser.parse(informationPointDtoAsJsonString, methodReference);
    informationPoint.ifPresent(ip -> {
        informationPointService.removeInformationPoint(ip);
        informationPointService.addInformationPoint(ip);
        LOG.trace(() -> "Information point " + ip + " modified");
    });
}
 
Example #13
Source File: ConsulController.java    From james with Apache License 2.0 5 votes vote down vote up
private void onInformationPointAdded(ConfigurationEvent event, InformationPointService informationPointService) {
    String methodReference = readMethodReference(event);
    String informationPointDtoAsJsonString = (String) event.getPropertyValue();

    Optional<InformationPoint> informationPoint =
            InformationPointDTOParser.parse(informationPointDtoAsJsonString, methodReference);
    informationPoint.ifPresent(ip -> {
        informationPointService.addInformationPoint(ip);
        LOG.trace(() -> "Information point " + ip + " added");
    });
}
 
Example #14
Source File: TestConfigurationSubscription.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.save();

    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub =
            new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);

    final AtomicInteger count = new AtomicInteger(1);
    conf.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            LOG.info("config changed {}", event);
            // Throw after so we actually see the update anyway.
            if (!event.isBeforeUpdate()) {
                count.getAndIncrement();
                throw new RuntimeException("config listener threw and exception");
            }
        }
    });

    int i = 0;
    int initial = 0;
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }

    initial = count.get();
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
}
 
Example #15
Source File: MessageResources.java    From unitime with Apache License 2.0 4 votes vote down vote up
public void configurationChanged(ConfigurationEvent arg0) {
	SessionListener.reloadMessageResources(basePath);
}
 
Example #16
Source File: TestConfigurationSubscription.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.save();

    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub =
            new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);

    final AtomicInteger count = new AtomicInteger(1);
    conf.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            LOG.info("config changed {}", event);
            // Throw after so we actually see the update anyway.
            if (!event.isBeforeUpdate()) {
                count.getAndIncrement();
                throw new RuntimeException("config listener threw and exception");
            }
        }
    });

    int i = 0;
    int initial = 0;
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }

    initial = count.get();
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
}
 
Example #17
Source File: ConsulController.java    From james with Apache License 2.0 4 votes vote down vote up
private String readMethodReference(ConfigurationEvent event) {
    return event.getPropertyName().replace('!', '#');
}