use of org.apache.flink.configuration.DelegatingConfiguration in project flink by apache.
the class MetricRegistryConfiguration method fromConfiguration.
// ------------------------------------------------------------------------
// Static factory methods
// ------------------------------------------------------------------------
/**
* Create a metric registry configuration object from the given {@link Configuration}.
*
* @param configuration to generate the metric registry configuration from
* @return Metric registry configuration generated from the configuration
*/
public static MetricRegistryConfiguration fromConfiguration(Configuration configuration) {
ScopeFormats scopeFormats;
try {
scopeFormats = createScopeConfig(configuration);
} catch (Exception e) {
LOG.warn("Failed to parse scope format, using default scope formats", e);
scopeFormats = new ScopeFormats();
}
char delim;
try {
delim = configuration.getString(ConfigConstants.METRICS_SCOPE_DELIMITER, ".").charAt(0);
} catch (Exception e) {
LOG.warn("Failed to parse delimiter, using default delimiter.", e);
delim = '.';
}
final String definedReporters = configuration.getString(ConfigConstants.METRICS_REPORTERS_LIST, null);
List<Tuple2<String, Configuration>> reporterConfigurations;
if (definedReporters == null) {
reporterConfigurations = Collections.emptyList();
} else {
String[] namedReporters = splitPattern.split(definedReporters);
reporterConfigurations = new ArrayList<>(namedReporters.length);
for (String namedReporter : namedReporters) {
DelegatingConfiguration delegatingConfiguration = new DelegatingConfiguration(configuration, ConfigConstants.METRICS_REPORTER_PREFIX + namedReporter + '.');
reporterConfigurations.add(Tuple2.of(namedReporter, (Configuration) delegatingConfiguration));
}
}
return new MetricRegistryConfiguration(scopeFormats, delim, reporterConfigurations);
}
use of org.apache.flink.configuration.DelegatingConfiguration in project flink by apache.
the class TaskConfig method setTypeComparatorFactory.
private void setTypeComparatorFactory(TypeComparatorFactory<?> factory, String classNameKey, String parametersPrefix) {
// sanity check the factory type
InstantiationUtil.checkForInstantiation(factory.getClass());
// store the type
this.config.setString(classNameKey, factory.getClass().getName());
// store the parameters
final DelegatingConfiguration parameters = new DelegatingConfiguration(this.config, parametersPrefix);
factory.writeParametersToConfig(parameters);
}
use of org.apache.flink.configuration.DelegatingConfiguration in project flink by apache.
the class TaskConfig method setTypeSerializerFactory.
// --------------------------------------------------------------------------------------------
// Miscellaneous
// --------------------------------------------------------------------------------------------
private void setTypeSerializerFactory(TypeSerializerFactory<?> factory, String classNameKey, String parametersPrefix) {
// sanity check the factory type
InstantiationUtil.checkForInstantiation(factory.getClass());
// store the type
this.config.setString(classNameKey, factory.getClass().getName());
// store the parameters
final DelegatingConfiguration parameters = new DelegatingConfiguration(this.config, parametersPrefix);
factory.writeParametersToConfig(parameters);
}
use of org.apache.flink.configuration.DelegatingConfiguration in project flink by apache.
the class TaskConfig method getTypeComparatorFactory.
private <T> TypeComparatorFactory<T> getTypeComparatorFactory(String classNameKey, String parametersPrefix, ClassLoader cl) {
// check the class name
final String className = this.config.getString(classNameKey, null);
if (className == null) {
return null;
}
// instantiate the class
@SuppressWarnings("unchecked") final Class<TypeComparatorFactory<T>> superClass = (Class<TypeComparatorFactory<T>>) (Class<?>) TypeComparatorFactory.class;
final TypeComparatorFactory<T> factory;
try {
Class<? extends TypeComparatorFactory<T>> clazz = Class.forName(className, true, cl).asSubclass(superClass);
factory = InstantiationUtil.instantiate(clazz, superClass);
} catch (ClassNotFoundException cnfex) {
throw new RuntimeException("The class '" + className + "', noted in the configuration as " + "comparator factory, could not be found. It is not part of the user code's class loader resources.");
} catch (ClassCastException ccex) {
throw new CorruptConfigurationException("The class noted in the configuration as the comparator factory " + "is no subclass of TypeComparatorFactory.");
}
// parameterize the comparator factory
final Configuration parameters = new DelegatingConfiguration(this.config, parametersPrefix);
try {
factory.readParametersFromConfig(parameters, cl);
} catch (ClassNotFoundException cnfex) {
throw new RuntimeException("The type serializer factory could not load its parameters from the " + "configuration due to missing classes.", cnfex);
}
return factory;
}
use of org.apache.flink.configuration.DelegatingConfiguration in project flink by apache.
the class TaskConfig method getTypeSerializerFactory.
private <T> TypeSerializerFactory<T> getTypeSerializerFactory(String classNameKey, String parametersPrefix, ClassLoader cl) {
// check the class name
final String className = this.config.getString(classNameKey, null);
if (className == null) {
return null;
}
// instantiate the class
@SuppressWarnings("unchecked") final Class<TypeSerializerFactory<T>> superClass = (Class<TypeSerializerFactory<T>>) (Class<?>) TypeSerializerFactory.class;
final TypeSerializerFactory<T> factory;
try {
Class<? extends TypeSerializerFactory<T>> clazz = Class.forName(className, true, cl).asSubclass(superClass);
factory = InstantiationUtil.instantiate(clazz, superClass);
} catch (ClassNotFoundException cnfex) {
throw new RuntimeException("The class '" + className + "', noted in the configuration as " + "serializer factory, could not be found. It is not part of the user code's class loader resources.");
} catch (ClassCastException ccex) {
throw new CorruptConfigurationException("The class noted in the configuration as the serializer factory " + "is no subclass of TypeSerializerFactory.");
}
// parameterize the comparator factory
final Configuration parameters = new DelegatingConfiguration(this.config, parametersPrefix);
try {
factory.readParametersFromConfig(parameters, cl);
} catch (ClassNotFoundException cnfex) {
throw new RuntimeException("The type serializer factory could not load its parameters from the " + "configuration due to missing classes.", cnfex);
}
return factory;
}
Aggregations