use of org.apache.ignite.internal.configuration.tree.ConstructableTreeNode in project ignite-3 by apache.
the class ConfigurationChanger method initializeDefaults.
/**
* Initializes the configuration storage - reads data and sets default values for missing configuration properties.
*
* @throws ConfigurationValidationException If configuration validation failed.
* @throws ConfigurationChangeException If configuration framework failed to add default values and save them to storage.
*/
public void initializeDefaults() throws ConfigurationValidationException, ConfigurationChangeException {
try {
ConfigurationSource defaultsCfgSource = new ConfigurationSource() {
/**
* {@inheritDoc}
*/
@Override
public void descend(ConstructableTreeNode node) {
addDefaults((InnerNode) node);
}
};
changeInternally(defaultsCfgSource).get(5, TimeUnit.SECONDS);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof ConfigurationValidationException) {
throw (ConfigurationValidationException) cause;
}
if (cause instanceof ConfigurationChangeException) {
throw (ConfigurationChangeException) cause;
}
throw new ConfigurationChangeException("Failed to write default configuration values into the storage " + storage.getClass(), e);
} catch (InterruptedException | TimeoutException e) {
throw new ConfigurationChangeException("Failed to initialize configuration storage " + storage.getClass(), e);
}
}
use of org.apache.ignite.internal.configuration.tree.ConstructableTreeNode in project ignite-3 by apache.
the class DynamicConfiguration method change.
/**
* {@inheritDoc}
*/
@Override
public final CompletableFuture<Void> change(Consumer<CHANGET> change) {
Objects.requireNonNull(change, "Configuration consumer cannot be null.");
if (listenOnly) {
throw listenOnlyException();
}
assert keys instanceof RandomAccess;
ConfigurationSource src = new ConfigurationSource() {
/**
* Current index in the {@code keys}.
*/
private int level = 0;
/**
* {@inheritDoc}
*/
@Override
public void descend(ConstructableTreeNode node) {
if (level == keys.size()) {
if (node instanceof InnerNode) {
// To support polymorphic configuration.
change.accept(((InnerNode) node).specificNode());
} else {
// To support namedList configuration.
change.accept((CHANGET) node);
}
} else {
node.construct(keys.get(level++), this, true);
}
}
/**
* {@inheritDoc}
*/
@Override
public void reset() {
level = 0;
}
};
// Use resulting tree as update request for the storage.
return changer.change(src);
}
use of org.apache.ignite.internal.configuration.tree.ConstructableTreeNode in project ignite-3 by apache.
the class ConfigurationChangerTest method source.
private static <CHANGET> ConfigurationSource source(RootKey<?, ? super CHANGET> rootKey, Consumer<CHANGET> changer) {
return new ConfigurationSource() {
@Override
public void descend(ConstructableTreeNode node) {
ConfigurationSource changerSrc = new ConfigurationSource() {
@Override
public void descend(ConstructableTreeNode node) {
changer.accept((CHANGET) node);
}
};
node.construct(rootKey.key(), changerSrc, true);
}
};
}
use of org.apache.ignite.internal.configuration.tree.ConstructableTreeNode in project ignite-3 by apache.
the class DynamicProperty method update.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> update(T newValue) {
Objects.requireNonNull(newValue, "Configuration value cannot be null.");
if (listenOnly) {
throw listenOnlyException();
}
if (readOnly) {
throw new ConfigurationReadOnlyException("Read only mode: " + keys);
}
assert keys instanceof RandomAccess;
assert !keys.isEmpty();
ConfigurationSource src = new ConfigurationSource() {
/**
* Current index in the {@code keys}.
*/
private int level = 0;
/**
* {@inheritDoc}
*/
@Override
public void descend(ConstructableTreeNode node) {
assert level < keys.size();
node.construct(keys.get(level++), this, true);
}
/**
* {@inheritDoc}
*/
@Override
public <T> T unwrap(Class<T> clazz) {
assert level == keys.size();
assert clazz.isInstance(newValue);
return clazz.cast(newValue);
}
/**
* {@inheritDoc}
*/
@Override
public void reset() {
level = 0;
}
};
// Use resulting tree as update request for the storage.
return changer.change(src);
}
Aggregations