public FunctionRegistry(DrillConfig config) { try { Set<Class<? extends CallProvider>> providerClasses = PathScanner.scanForImplementations( CallProvider.class, config.getStringList(CommonConstants.LOGICAL_FUNCTION_SCAN_PACKAGES)); Map<String, FunctionDefinition> funcs = new HashMap<String, FunctionDefinition>(); for (Class<? extends CallProvider> c : providerClasses) { CallProvider p = c.newInstance(); FunctionDefinition[] defs = p.getFunctionDefintions(); for (FunctionDefinition d : defs) { for (String rn : d.getRegisteredNames()) { FunctionDefinition d2 = funcs.put(rn, d); // logger.debug("Registering function {}", d); if (d2 != null) { throw new ExceptionInInitializerError( String.format( "Failure while registering functions. The function %s tried to register with the name %s but the function %s already registered with that name.", d.getName(), rn, d2.getName())); } } } } funcMap = funcs; } catch (Exception e) { throw new RuntimeException("Failure while setting up FunctionRegistry.", e); } }
public static synchronized Class<?>[] getSubTypes(DrillConfig config) { List<String> packages = config.getStringList(CommonConstants.STORAGE_PLUGIN_CONFIG_SCAN_PACKAGES); Class<?>[] sec = PathScanner.scanForImplementationsArr(FormatPluginConfig.class, packages); logger.debug("Adding Format Plugin Configs including {}", (Object) sec); return sec; }
/** * Use reflection to scan for implementations of {@see FormatPlugin}. * * @param config - Drill configuration object, used to find the packages to scan * @return - list of classes that implement the interface. */ public static synchronized Class<?>[] getSubTypes(final DrillConfig config) { final List<String> packages = config.getStringList(CommonConstants.STORAGE_PLUGIN_CONFIG_SCAN_PACKAGES); final Class<?>[] pluginClasses = PathScanner.scanForImplementationsArr(FormatPluginConfig.class, packages); final String lineBrokenList = pluginClasses.length == 0 ? "" : "\n\t- " + Joiner.on("\n\t- ").join(pluginClasses); logger.debug( "Found {} format plugin configuration classes: {}.", pluginClasses.length, lineBrokenList); return pluginClasses; }
public DrillFunctionImplementationRegistry(DrillConfig config) { FunctionConverter converter = new FunctionConverter(); Set<Class<? extends DrillFunc>> providerClasses = PathScanner.scanForImplementations( DrillFunc.class, config.getStringList(ExecConstants.FUNCTION_PACKAGES)); for (Class<? extends DrillFunc> clazz : providerClasses) { DrillFuncHolder holder = converter.getHolder(clazz); if (holder != null) { // register handle for each name the function can be referred to String[] names = holder.getRegisteredNames(); for (String name : names) methods.put(name, holder); } else { logger.warn("Unable to initialize function for class {}", clazz.getName()); } } }