private PropertyFactory(String prefix, String propName, String workerName) { this.global = DynamicProperty.getInstance(prefix + "." + propName); this.local = DynamicProperty.getInstance(prefix + "." + workerName + "." + propName); }
/** * Get the current value from the underlying DynamicProperty */ public Integer get() { return prop.getInteger(defaultValue); }
@Override public String getValue() { return prop.getString(defaultValue); } }
public QpsControllerManager setGlobalQpsController(String globalConfigKey) { DynamicProperty globalQpsProperty = DynamicProperty.getInstance(globalConfigKey); QpsController qpsController = new QpsController(globalConfigKey, globalQpsProperty.getInteger()); globalQpsProperty.addCallback(() -> { qpsController.setQpsLimit(globalQpsProperty.getInteger()); LOGGER.info("Global qps limit update, value = [{}]", globalQpsProperty.getInteger()); }); this.globalQpsController = qpsController; return this; }
protected PropertyWrapper(String propName, V defaultValue) { this.prop = DynamicProperty.getInstance(propName); this.defaultValue = defaultValue; Class<?> c = getClass(); this.prop.addCallback(callback); callbackList.add(callback); this.prop.addValidator(new PropertyChangeValidator() { @Override public void validate(String newValue) { if (this.prop.getString() != null) { this.validate(this.prop.getString()); prop.updateValue(defaultValue);
private void createQpsControllerIfNotExist(String configKey) { if (configQpsControllerMap.keySet().contains(configKey)) { return; } LOGGER.info("Create qpsController, configKey = [{}]", configKey); DynamicProperty property = getDynamicProperty(configKey); QpsController qpsController = new QpsController(configKey, property.getInteger()); configQpsControllerMap.put(configKey, qpsController); property.addCallback(() -> { qpsController.setQpsLimit(property.getInteger()); LOGGER.info("Qps limit updated, configKey = [{}], value = [{}]", configKey, property.getString()); updateObjMap(configKey); }); }
public static void addCallback(String property, Runnable callback) { final DynamicProperty dynamicProperty = DynamicProperty.getInstance(property); dynamicProperty.addCallback(callback); } }
@Override public String apply(@Nullable String input) { return DynamicProperty.getInstance(input).getString(); }
/** * Get the current value from the underlying DynamicProperty */ public Boolean get() { return prop.getBoolean(defaultValue); }
private final void propertyChangedInternal() { if (prop.getString() != null) { try { values = mapper.readValue(prop.getString(), new TypeReference<List<Value<T>>>(){}); } catch (Throwable e) { // this could be that the property is not set up as JSON based multi-dimensional contextual property // and only has one textual value, try to parse this textual value Optional<T> cachedValue = prop.getCachedValue(classType); if (cachedValue.isPresent()) { T value = cachedValue.get(); values = Lists.newArrayList(); values.add(new Value<T>(value)); } else { values = null; } if (values == null) { throw new RuntimeException("Unable to parse the property value: " + prop.getString(), e); } } } else { values = null; } }
private static void addCallback(Runnable callback, PropertyWrapper<?> wrapper) { if (callback != null) { wrapper.prop.addCallback(callback); } }
/** * Get the current value from the underlying DynamicProperty */ public Long get() { return prop.getLong(defaultValue); }
/** * Gets the DynamicProperty for a given property name. * This may be a previously constructed object, * or an object constructed on-demand to satisfy the request. * * @param propName the name of the property * @return a DynamicProperty object that holds the cached value of * the configuration property named {@code propName} */ public static DynamicProperty getInstance(String propName) { // This is to ensure that a configuration source is registered with // DynamicProperty if (dynamicPropertySupportImpl == null) { DynamicPropertyFactory.getInstance(); } DynamicProperty prop = ALL_PROPS.get(propName); if (prop == null) { prop = new DynamicProperty(propName); DynamicProperty oldProp = ALL_PROPS.putIfAbsent(propName, prop); if (oldProp != null) { prop = oldProp; } } return prop; }
public DynamicPropertyBasedPoolStrategy(final int maxConnections, String propertyName) { super(maxConnections); poolSizeProperty = DynamicProperty.getInstance(propertyName); setMaxConnections(poolSizeProperty.getInteger(maxConnections)); poolSizeProperty.addCallback(new Runnable() { @Override public void run() { setMaxConnections(poolSizeProperty.getInteger(maxConnections)); }; }); }
protected PropertyWrapper(String propName, V defaultValue) { this.prop = DynamicProperty.getInstance(propName); this.defaultValue = defaultValue; Class<?> c = getClass(); this.prop.addCallback(callback); callbackList.add(callback); this.prop.addValidator(new PropertyChangeValidator() { @Override public void validate(String newValue) { if (this.prop.getString() != null) { this.validate(this.prop.getString()); prop.updateValue(defaultValue);
private void createQpsControllerIfNotExist(String configKey) { if (configQpsControllerMap.keySet().contains(configKey)) { return; } LOGGER.info("Create qpsController, configKey = [{}]", configKey); DynamicProperty property = getDynamicProperty(configKey); QpsController qpsController = new QpsController(configKey, property.getInteger()); configQpsControllerMap.put(configKey, qpsController); property.addCallback(() -> { qpsController.setQpsLimit(property.getInteger()); LOGGER.info("Qps limit updated, configKey = [{}], value = [{}]", configKey, property.getString()); updateObjMap(configKey); }); }
private void initConfig(String key) { if (watchedKeySet.contains(key)) { return; } watchedKeySet.add(key); String configKey = Config.PROVIDER_LIMIT_KEY_PREFIX + key; DynamicProperty property = DynamicProperty.getInstance(configKey); initQpsLimit(key, getIntegerLimitProperty(property)); property.addCallback(() -> { updateQpsLimit(key, getIntegerLimitProperty(property)); QpsController qpsController = findReference(key); objMap.put(key, qpsController); }); }
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE") public String apply(@Nullable String input) { return DynamicProperty.getInstance(input).getString(); }
@Override public Boolean getValue() { return prop.getBoolean(defaultValue); } }