/** * Resolves a function by name. * @param functionName The name of the function to resolve. * @return The executable StellarFunction. */ @Override public StellarFunction apply(String functionName) { StellarFunctionInfo info = functions.get().get(functionName); if(info == null) { throw new IllegalStateException(format("Unknown function: `%s`", functionName)); } return info.getFunction(); }
for (StellarFunctionInfo info : getFunctionInfo()) { try { info.getFunction().close(); } catch (Throwable t) { errors.put(info.getName(), t);
/** * Performs the core process of function resolution. */ protected Map<String, StellarFunctionInfo> resolveFunctions() { // maps a function name to its definition Map<String, StellarFunctionInfo> functions = new HashMap<>(); for(Class<? extends StellarFunction> clazz : resolvables()) { StellarFunctionInfo fn = resolveFunction(clazz); if(fn != null) { // check for duplicate function names StellarFunctionInfo fnSameName = functions.get(fn.getName()); if (fnSameName != null && ObjectUtils.notEqual(fnSameName, fn)) { LOG.warn("Namespace conflict: duplicate function names; `{}` implemented by [{}, {}]", fn.getName(), fnSameName.getFunction(), fn.getFunction()); } functions.put(fn.getName(), fn); } } return functions; }
@Test public void testNotifyFunctionListeners() throws Exception { // setup an executor notified = false; Properties props = new Properties(); DefaultStellarShellExecutor executor = new DefaultStellarShellExecutor(props, Optional.empty()); // setup listener notified = false; executor.addFunctionListener((fn) -> { assertNotNull(fn); assertNotNull(fn.getName()); assertNotNull(fn.getFunction()); notified = true; }); // initialize... magics should be setup during initialization executor.init(); assertTrue(notified); }