use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class CachedGoConfig method saveValidConfigToCacheAndNotifyEntityConfigChangeListeners.
private <T> void saveValidConfigToCacheAndNotifyEntityConfigChangeListeners(EntityConfigSaveResult<T> saveResult) {
saveValidConfigToCache(saveResult.getConfigHolder());
LOGGER.info("About to notify {} config listeners", saveResult.getEntityConfig().getClass().getName());
for (ConfigChangedListener listener : listeners) {
if (listener instanceof EntityConfigChangedListener<?> && ((EntityConfigChangedListener) listener).shouldCareAbout(saveResult.getEntityConfig())) {
try {
long startTime = System.currentTimeMillis();
EntityConfigChangedListener<T> entityConfigChangedListener = (EntityConfigChangedListener<T>) listener;
entityConfigChangedListener.onEntityConfigChange(saveResult.getEntityConfig());
LOGGER.debug("Notifying {} took (in ms): {}", listener.getClass(), (System.currentTimeMillis() - startTime));
} catch (Exception e) {
LOGGER.error("failed to fire config changed event for listener: {}", listener, e);
}
}
}
LOGGER.info("Finished notifying {} config listeners", saveResult.getEntityConfig().getClass().getName());
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class CachedGoConfig method notifyListeners.
private synchronized void notifyListeners(CruiseConfig newCruiseConfig) {
LOGGER.info("About to notify config listeners");
for (ConfigChangedListener listener : listeners) {
try {
listener.onConfigChange(newCruiseConfig);
} catch (Exception e) {
LOGGER.error("Failed to fire config changed event for listener: {}", listener, e);
}
}
LOGGER.info("Finished notifying all listeners");
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class CachedGoConfigTest method shouldNotNotifyWhenConfigIsNullDuringRegistration.
@Test
public void shouldNotNotifyWhenConfigIsNullDuringRegistration() throws Exception {
final ConfigChangedListener listener = mock(ConfigChangedListener.class);
cachedGoConfig.registerListener(listener);
verifyNoMoreInteractions(listener);
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class CcTrayActivityListenerTest method shouldInvokeConfigChangeHandlerWhenSecurityConfigChanges.
@Test
public void shouldInvokeConfigChangeHandlerWhenSecurityConfigChanges() throws InterruptedException {
CcTrayConfigChangeHandler ccTrayConfigChangeHandler = mock(CcTrayConfigChangeHandler.class);
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
doNothing().when(goConfigService).register(captor.capture());
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, mock(CcTrayJobStatusChangeHandler.class), mock(CcTrayStageStatusChangeHandler.class), ccTrayConfigChangeHandler);
listener.initialize();
listener.startDaemon();
List<ConfigChangedListener> listeners = captor.getAllValues();
assertThat(listeners.get(2) instanceof SecurityConfigChangeListener, is(true));
SecurityConfigChangeListener securityConfigChangeListener = (SecurityConfigChangeListener) listeners.get(2);
securityConfigChangeListener.onEntityConfigChange(new PluginRoleConfig());
waitForProcessingToHappen();
verify(ccTrayConfigChangeHandler).call(cruiseConfig);
}
Aggregations