private static <T> T createInstance(String className, ClassLoader clsLoader, Class<T> baseClass) { if (StringUtils.isEmpty(className)) { return null; } else { return Reflections.createInstance(className, baseClass, clsLoader); } } }
public static Class<?> getSinkType(String className, ClassLoader classLoader) { Object userClass = Reflections.createInstance(className, classLoader); Class<?> typeArg; Sink sink = (Sink) userClass; if (sink == null) { throw new IllegalArgumentException(String.format("The Pulsar sink class %s could not be instantiated", className)); } typeArg = TypeResolver.resolveRawArgument(Sink.class, sink.getClass()); return typeArg; }
public static Object createInstance(String userClassName, java.io.File jar) { try { return createInstance(userClassName, loadJar(jar)); } catch (Exception ex) { return null; } }
public static Class<?> getSourceType(String className, ClassLoader classloader) { Object userClass = Reflections.createInstance(className, classloader); Class<?> typeArg; Source source = (Source) userClass; if (source == null) { throw new IllegalArgumentException(String.format("The Pulsar source class %s could not be instantiated", className)); } typeArg = TypeResolver.resolveRawArgument(Source.class, source.getClass()); return typeArg; }
private static void validateSerDeType(String serdeClassName, Class<?> typeArg, ClassLoader clsLoader) { SerDe<?> serDe = (SerDe<?>) Reflections.createInstance(serdeClassName, clsLoader); if (serDe == null) { throw new IllegalArgumentException(String.format("The SerDe class %s does not exist", serdeClassName)); } Class<?>[] serDeTypes = TypeResolver.resolveRawArguments(SerDe.class, serDe.getClass()); // type inheritance information seems to be lost in generic type // load the actual type class for verification Class<?> fnInputClass; Class<?> serdeInputClass; try { fnInputClass = Class.forName(typeArg.getName(), true, clsLoader); serdeInputClass = Class.forName(serDeTypes[0].getName(), true, clsLoader); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Failed to load type class", e); } if (!fnInputClass.isAssignableFrom(serdeInputClass)) { throw new IllegalArgumentException( "Serializer type mismatch " + typeArg + " vs " + serDeTypes[0]); } }
private java.util.function.Function<Collection<I>, O> intializeUserFunction(WindowConfig windowConfig) { String actualWindowFunctionClassName = windowConfig.getActualWindowFunctionClassName(); ClassLoader clsLoader = Thread.currentThread().getContextClassLoader(); Object userClassObject = Reflections.createInstance( actualWindowFunctionClassName, clsLoader); if (userClassObject instanceof java.util.function.Function) { Class<?>[] typeArgs = TypeResolver.resolveRawArguments( java.util.function.Function.class, userClassObject.getClass()); if (typeArgs[0].equals(Collection.class)) { return (java.util.function.Function) userClassObject; } else { throw new IllegalArgumentException("Window function must take a collection as input"); } } else { throw new IllegalArgumentException("Window function does not implement the correct interface"); } }
private static void validateCustomSchemaType(String schemaClassName, Class<?> typeArg, ClassLoader clsLoader, boolean input) { Schema<?> schema = (Schema<?>) Reflections.createInstance(schemaClassName, clsLoader); if (schema == null) { throw new IllegalArgumentException(String.format("The Schema class %s does not exist",
SerDe serDe = (SerDe) Reflections.createInstance(inputSerializer, clsLoader); if (serDe == null) { throw new IllegalArgumentException(String.format("The SerDe class %s does not exist",
object = Reflections.createInstance( sinkSpec.getClassName(), Thread.currentThread().getContextClassLoader());
/** * NOTE: this method should be called in the instance thread, in order to make class loading work. */ JavaInstance setupJavaInstance(ContextImpl contextImpl) throws Exception { // initialize the thread context ThreadContext.put("function", FunctionDetailsUtils.getFullyQualifiedName(instanceConfig.getFunctionDetails())); ThreadContext.put("functionname", instanceConfig.getFunctionDetails().getName()); ThreadContext.put("instance", instanceConfig.getInstanceName()); log.info("Starting Java Instance {} : \n Details = {}", instanceConfig.getFunctionDetails().getName(), instanceConfig.getFunctionDetails()); // start the function thread loadJars(); ClassLoader clsLoader = Thread.currentThread().getContextClassLoader(); Object object = Reflections.createInstance( instanceConfig.getFunctionDetails().getClassName(), clsLoader); if (!(object instanceof Function) && !(object instanceof java.util.function.Function)) { throw new RuntimeException("User class must either be Function or java.util.Function"); } // start the state table setupStateTable(); // start the output producer setupOutput(contextImpl); // start the input consumer setupInput(contextImpl); // start any log topic handler setupLogHandler(); return new JavaInstance(contextImpl, object); }
FunctionDetailsUtils.getFullyQualifiedName(this.instanceConfig.getFunctionDetails())); } else { object = Reflections.createInstance( sourceSpec.getClassName(), Thread.currentThread().getContextClassLoader());