@Override public Map<String, Tuple<A, B>> getValue(Settings current, Settings previous) { Map<String, Tuple<A, B>> map = new HashMap<>(); BiConsumer<String, A> aConsumer = (key, value) -> { assert map.containsKey(key) == false : "duplicate key: " + key; map.put(key, new Tuple<>(value, settingB.getConcreteSettingForNamespace(key).get(current))); }; BiConsumer<String, B> bConsumer = (key, value) -> { Tuple<A, B> abTuple = map.get(key); if (abTuple != null) { map.put(key, new Tuple<>(abTuple.v1(), value)); } else { assert settingA.getConcreteSettingForNamespace(key).get(current).equals(settingA.getConcreteSettingForNamespace (key).get(previous)) : "expected: " + settingA.getConcreteSettingForNamespace(key).get(current) + " but was " + settingA.getConcreteSettingForNamespace(key).get(previous); map.put(key, new Tuple<>(settingA.getConcreteSettingForNamespace(key).get(current), value)); } }; SettingUpdater<Map<SettingUpdater<A>, A>> affixUpdaterA = settingA.newAffixUpdater(aConsumer, logger, (a,b) ->{}); SettingUpdater<Map<SettingUpdater<B>, B>> affixUpdaterB = settingB.newAffixUpdater(bConsumer, logger, (a,b) ->{}); affixUpdaterA.apply(current, previous); affixUpdaterB.apply(current, previous); for (Map.Entry<String, Tuple<A, B>> entry : map.entrySet()) { validator.accept(entry.getKey(), entry.getValue()); } return Collections.unmodifiableMap(map); }
/** * Validates the given settings by running it through all update listeners without applying it. This * method will not change any settings but will fail if any of the settings can't be applied. */ public synchronized Settings validateUpdate(Settings settings) { final Settings current = Settings.builder().put(this.settings).put(settings).build(); final Settings previous = Settings.builder().put(this.settings).put(this.lastSettingsApplied).build(); List<RuntimeException> exceptions = new ArrayList<>(); for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { // ensure running this through the updater / dynamic validator // don't check if the value has changed we wanna test this anyways settingUpdater.getValue(current, previous); } catch (RuntimeException ex) { exceptions.add(ex); logger.debug(() -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex); } } // here we are exhaustive and record all settings that failed. ExceptionsHelper.rethrowAndSuppress(exceptions); return current; }
for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { applyRunnables.add(settingUpdater.updater(current, previous)); } catch (Exception ex) { logger.warn(() -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex);
for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { applyRunnables.add(settingUpdater.updater(current, previous)); } catch (Exception ex) { logger.warn(() -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex);
for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { applyRunnables.add(settingUpdater.updater(current, previous)); } catch (Exception ex) { logger.warn(
for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { applyRunnables.add(settingUpdater.updater(current, previous)); } catch (Exception ex) { logger.warn(() -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex);
@Override public Map<String, Tuple<A, B>> getValue(Settings current, Settings previous) { Map<String, Tuple<A, B>> map = new HashMap<>(); BiConsumer<String, A> aConsumer = (key, value) -> { assert map.containsKey(key) == false : "duplicate key: " + key; map.put(key, new Tuple<>(value, settingB.getConcreteSettingForNamespace(key).get(current))); }; BiConsumer<String, B> bConsumer = (key, value) -> { Tuple<A, B> abTuple = map.get(key); if (abTuple != null) { map.put(key, new Tuple<>(abTuple.v1(), value)); } else { assert settingA.getConcreteSettingForNamespace(key).get(current).equals(settingA.getConcreteSettingForNamespace (key).get(previous)) : "expected: " + settingA.getConcreteSettingForNamespace(key).get(current) + " but was " + settingA.getConcreteSettingForNamespace(key).get(previous); map.put(key, new Tuple<>(settingA.getConcreteSettingForNamespace(key).get(current), value)); } }; SettingUpdater<Map<SettingUpdater<A>, A>> affixUpdaterA = settingA.newAffixUpdater(aConsumer, logger, (a,b) ->{}); SettingUpdater<Map<SettingUpdater<B>, B>> affixUpdaterB = settingB.newAffixUpdater(bConsumer, logger, (a,b) ->{}); affixUpdaterA.apply(current, previous); affixUpdaterB.apply(current, previous); for (Map.Entry<String, Tuple<A, B>> entry : map.entrySet()) { validator.accept(entry.getKey(), entry.getValue()); } return Collections.unmodifiableMap(map); }
/** * Validates the given settings by running it through all update listeners without applying it. This * method will not change any settings but will fail if any of the settings can't be applied. */ public synchronized Settings validateUpdate(Settings settings) { final Settings current = Settings.builder().put(this.settings).put(settings).build(); final Settings previous = Settings.builder().put(this.settings).put(this.lastSettingsApplied).build(); List<RuntimeException> exceptions = new ArrayList<>(); for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { // ensure running this through the updater / dynamic validator // don't check if the value has changed we wanna test this anyways settingUpdater.getValue(current, previous); } catch (RuntimeException ex) { exceptions.add(ex); logger.debug(() -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex); } } // here we are exhaustive and record all settings that failed. ExceptionsHelper.rethrowAndSuppress(exceptions); return current; }
/** * Validates the given settings by running it through all update listeners without applying it. This * method will not change any settings but will fail if any of the settings can't be applied. */ public synchronized Settings validateUpdate(Settings settings) { final Settings current = Settings.builder().put(this.settings).put(settings).build(); final Settings previous = Settings.builder().put(this.settings).put(this.lastSettingsApplied).build(); List<RuntimeException> exceptions = new ArrayList<>(); for (SettingUpdater<?> settingUpdater : settingUpdaters) { try { // ensure running this through the updater / dynamic validator // don't check if the value has changed we wanna test this anyways settingUpdater.getValue(current, previous); } catch (RuntimeException ex) { exceptions.add(ex); logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to prepareCommit settings for [{}]", settingUpdater), ex); } } // here we are exhaustive and record all settings that failed. ExceptionsHelper.rethrowAndSuppress(exceptions); return current; }
@Override public boolean hasChanged(Settings current, Settings previous) { return affixUpdaterA.hasChanged(current, previous) || affixUpdaterB.hasChanged(current, previous); }
/** * Returns a callable runnable that calls {@link #apply(Object, Settings, Settings)} if the settings * actually changed. This allows to defer the update to a later point in time while keeping type safety. * If the value didn't change the returned runnable is a noop. */ default Runnable updater(Settings current, Settings previous) { if (hasChanged(current, previous)) { T value = getValue(current, previous); return () -> { apply(value, current, previous);}; } return () -> {}; } }
/** * Returns a callable runnable that calls {@link #apply(Object, Settings, Settings)} if the settings * actually changed. This allows to defer the update to a later point in time while keeping type safety. * If the value didn't change the returned runnable is a noop. */ default Runnable updater(Settings current, Settings previous) { if (hasChanged(current, previous)) { T value = getValue(current, previous); return () -> { apply(value, current, previous);}; } return () -> {}; } }
/** * Updates this updaters value if it has changed. * @return <code>true</code> iff the value has been updated. */ default boolean apply(Settings current, Settings previous) { if (hasChanged(current, previous)) { T value = getValue(current, previous); apply(value, current, previous); return true; } return false; }
/** * Updates this updaters value if it has changed. * @return <code>true</code> iff the value has been updated. */ default boolean apply(Settings current, Settings previous) { if (hasChanged(current, previous)) { T value = getValue(current, previous); apply(value, current, previous); return true; } return false; }
/** * Returns a callable runnable that calls {@link #apply(Object, Settings, Settings)} if the settings * actually changed. This allows to defer the update to a later point in time while keeping type safety. * If the value didn't change the returned runnable is a noop. */ default Runnable updater(Settings current, Settings previous) { if (hasChanged(current, previous)) { T value = getValue(current, previous); return () -> { apply(value, current, previous);}; } return () -> {}; } }
@Override public boolean hasChanged(Settings current, Settings previous) { return affixUpdaterA.hasChanged(current, previous) || affixUpdaterB.hasChanged(current, previous); }
/** * Updates this updaters value if it has changed. * @return <code>true</code> iff the value has been updated. */ default boolean apply(Settings current, Settings previous) { if (hasChanged(current, previous)) { T value = getValue(current, previous); apply(value, current, previous); return true; } return false; }