Search in sources :

Example 1 with TypeComparatorFactory

use of org.apache.flink.api.common.typeutils.TypeComparatorFactory 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;
}
Also used : DelegatingConfiguration(org.apache.flink.configuration.DelegatingConfiguration) Configuration(org.apache.flink.configuration.Configuration) TypeComparatorFactory(org.apache.flink.api.common.typeutils.TypeComparatorFactory) DelegatingConfiguration(org.apache.flink.configuration.DelegatingConfiguration)

Aggregations

TypeComparatorFactory (org.apache.flink.api.common.typeutils.TypeComparatorFactory)1 Configuration (org.apache.flink.configuration.Configuration)1 DelegatingConfiguration (org.apache.flink.configuration.DelegatingConfiguration)1