public Class<?> defineClass(String name, byte[] bytes) throws ClassFormatError { return defineClass(name, bytes, 0, bytes.length); }
@SuppressWarnings("unchecked") public <T> Class<? extends T> generate(Class<T> baseClass, Class<?> delegateClass, String genericSignature) { ClassWriter cw = new ClassWriter(0); int number = counter.getAndIncrement(); byte[] bytes = writeClass(cw, baseClass, delegateClass, genericSignature, number); String generatedName = baseClass.getName() + SUFFIX + "_" + number; BytecodeClassLoader bytecodeClassLoader = new BytecodeClassLoader(URI.create("BytecodeClassLoader"), getClass().getClassLoader()); bytecodeClassLoader.addParent(delegateClass.getClassLoader()); return (Class<? extends T>) bytecodeClassLoader.defineClass(generatedName, bytes); }
@SuppressWarnings("unchecked") public <T> Class<? extends T> generate(Class<T> baseClass, Class<?> delegateClass, String genericSignature) { ClassWriter cw = new ClassWriter(0); int number = counter.getAndIncrement(); byte[] bytes = writeClass(cw, baseClass, delegateClass, genericSignature, number); String generatedName = baseClass.getName() + SUFFIX + "_" + number; BytecodeClassLoader bytecodeClassLoader = new BytecodeClassLoader(URI.create("BytecodeClassLoader"), getClass().getClassLoader()); bytecodeClassLoader.addParent(delegateClass.getClassLoader()); return (Class<? extends T>) bytecodeClassLoader.defineClass(generatedName, bytes); }
public <T> T createMonitor(Class<T> type, Monitorable monitorable, String destination) throws Fabric3Exception { if (destination == null) { destination = DEFAULT_DESTINATION; } String proxyClassName = type.getName().replace("$", "") + "_Proxy"; int destinationIndex = router.getDestinationIndex(destination); ClassLoader loader = type.getClassLoader(); Map<Method, DispatchInfo> levels = new LinkedHashMap<>(); Method[] methods = type.getMethods(); for (Method method : methods) { DispatchInfo info = createDispatchInfo(type, loader, method); levels.put(method, info); } byte[] classBytes = generateClass(type, ClassWriter.COMPUTE_FRAMES); BytecodeClassLoader bytecodeClassLoader = getClassLoader(type); Class<?> clazz = bytecodeClassLoader.defineClass(proxyClassName, classBytes); try { Collection<DispatchInfo> values = levels.values(); DispatchInfo[] infos = values.toArray(new DispatchInfo[values.size()]); AbstractMonitorHandler handler = (AbstractMonitorHandler) clazz.getConstructor().newInstance(); handler.init(destinationIndex, monitorable, router, infos, enabled); return type.cast(handler); } catch (InvocationTargetException | IllegalAccessException | InstantiationException | NoSuchMethodException e) { throw new Fabric3Exception(e); } }
Class<?> clazz = bytecodeClassLoader.defineClass(proxyClassName, classBytes); try { Collection<DispatchInfo> values = levels.values();