@Test public void require_that_new_config_is_detected_in_time() throws IOException, InterruptedException { writeConfig("intval", "23"); ConfigSubscriber subscriber = new ConfigSubscriber(new FileSource(TEST_TYPES_FILE)); ConfigSubscription<SimpletypesConfig> sub = new FileConfigSubscription<>( new ConfigKey<>(SimpletypesConfig.class, ""), subscriber, TEST_TYPES_FILE); assertTrue(sub.nextConfig(1000)); assertThat(sub.getConfigState().getConfig().intval(), is(23)); Thread.sleep(1000); writeConfig("intval", "33"); assertTrue(sub.nextConfig(1000)); assertThat(sub.getConfigState().getConfig().intval(), is(33)); }
@Override public boolean nextConfig(long timeout) { if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: "+file); if (checkReloaded()) { log.log(FINE, "User forced config reload at " + System.currentTimeMillis()); setConfigIfChanged(updateConfig()); ConfigState<T> configState = getConfigState(); log.log(FINE, "Config updated at " + System.currentTimeMillis() + ", changed: " + configState.isConfigChanged()); log.log(FINE, "Config: " + configState.getConfig().toString()); return true; } if (file.lastModified()!=ts) { setConfigIncGen(updateConfig()); return true; } try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new ConfigInterruptedException(e); } return false; }
FileConfigSubscription extends ConfigSubscription<T> { @Override public boolean nextConfig(long timeout) { if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: "+file); if (checkReloaded()) { log.log(FINE, "User forced config reload at " + System.currentTimeMillis()); setConfigIfChanged(updateConfig()); ConfigState<T> configState = getConfigState(); log.log(FINE, "Config updated at " + System.currentTimeMillis() + ", changed: " + configState.isConfigChanged()); log.log(FINE, "Config: " + configState.getConfig().toString()); return true; } if (file.lastModified()!=ts) { setConfigIncGen(updateConfig()); return true; } try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new ConfigInterruptedException(e); } return false; } }
FileConfigSubscription extends ConfigSubscription<T> { @Override public boolean nextConfig(long timeout) { if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: "+file); if (checkReloaded()) { log.log(FINE, "User forced config reload at " + System.currentTimeMillis()); setConfigIfChanged(updateConfig()); ConfigState<T> configState = getConfigState(); log.log(FINE, "Config updated at " + System.currentTimeMillis() + ", changed: " + configState.isConfigChanged()); log.log(FINE, "Config: " + configState.getConfig().toString()); return true; } if (file.lastModified()!=ts) { setConfigIncGen(updateConfig()); return true; } try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new ConfigInterruptedException(e); } return false; } FileConfigSubscription(ConfigKey<T> key, ConfigSubscriber subscriber, File f); }
FileConfigSubscription extends ConfigSubscription<T> { @Override public boolean nextConfig(long timeout) { if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: "+file); if (checkReloaded()) { log.log(FINE, "User forced config reload at " + System.currentTimeMillis()); setConfigIfChanged(updateConfig()); ConfigState<T> configState = getConfigState(); log.log(FINE, "Config updated at " + System.currentTimeMillis() + ", changed: " + configState.isConfigChanged()); log.log(FINE, "Config: " + configState.getConfig().toString()); return true; } if (file.lastModified()!=ts) { setConfigIncGen(updateConfig()); return true; } try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new ConfigInterruptedException(e); } return false; } FileConfigSubscription(ConfigKey<T> key, ConfigSubscriber subscriber, File f); @Override boolean nextConfig(long timeout); @Override boolean subscribe(long timeout); }
FileConfigSubscription extends ConfigSubscription<T> { @Override public boolean nextConfig(long timeout) { if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: "+file); if (checkReloaded()) { log.log(FINE, "User forced config reload at " + System.currentTimeMillis()); setConfigIfChanged(updateConfig()); ConfigState<T> configState = getConfigState(); log.log(FINE, "Config updated at " + System.currentTimeMillis() + ", changed: " + configState.isConfigChanged()); log.log(FINE, "Config: " + configState.getConfig().toString()); return true; } if (file.lastModified()!=ts) { setConfigIncGen(updateConfig()); return true; } try { Thread.sleep(timeout); } catch (InterruptedException e) { throw new ConfigInterruptedException(e); } return false; } FileConfigSubscription(ConfigKey<T> key, ConfigSubscriber subscriber, File f); @Override boolean nextConfig(long timeout); @Override boolean subscribe(long timeout);  }