From 8f46518b06d235f0f8487dcb8f1f2b95246baec0 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Fri, 21 Oct 2022 10:06:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A7=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E7=B1=BB=E5=8A=A0=E8=BD=BD=E5=99=A8=EF=BC=88=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E6=9B=BF=E6=8D=A2=E4=B8=BA=E6=96=B0=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/aop/proxy/AsgcProxyFactory.java | 1 - .../core/aop/proxy/ProxyClassLoader.java | 80 ------------------- 2 files changed, 81 deletions(-) delete mode 100644 neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyClassLoader.java diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyFactory.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyFactory.java index aa0acdc1..4df457f3 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyFactory.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/AsgcProxyFactory.java @@ -40,7 +40,6 @@ public class AsgcProxyFactory implements ProxyFactory { private static final String classNameTemplate = "%s" + SYMBOLIC + "%s"; private static AtomicLong proxyClassCounter = new AtomicLong(); private AsgcCompiler compiler = new AsgcCompiler(); - private ProxyClassLoader classLoader = new ProxyClassLoader(); @Override public T get(Class targetType) throws Exception { diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyClassLoader.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyClassLoader.java deleted file mode 100644 index 016ee66b..00000000 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyClassLoader.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2022 aoshiguchen - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package fun.asgc.neutrino.core.aop.proxy; - -import fun.asgc.neutrino.core.base.GlobalConfig; -import fun.asgc.neutrino.core.util.FileUtil; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 代理类加载器 - * @author: aoshiguchen - * @date: 2022/6/24 - */ -public class ProxyClassLoader extends ClassLoader { - - protected Map byteCodeMap = new ConcurrentHashMap<>(); - - static { - registerAsParallelCapable(); - } - - public ProxyClassLoader() { - super(getParentClassLoader()); - } - - protected static ClassLoader getParentClassLoader() { - ClassLoader ret = Thread.currentThread().getContextClassLoader(); - return ret != null ? ret : ProxyClassLoader.class.getClassLoader(); - } - - public Class loadProxyClass(ProxyClass proxyClass) { - if (null != proxyClass.getByteCode()) { - for (Map.Entry e : proxyClass.getByteCode().entrySet()) { - byteCodeMap.putIfAbsent(e.getKey(), e.getValue()); - } - } - - try { - return loadClass(proxyClass.getPkg() + "." + proxyClass.getName()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } - - @Override - protected Class findClass(String name) throws ClassNotFoundException { - byte[] bytes = byteCodeMap.get(name); - if (null == bytes) { - bytes = FileUtil.readBytes( GlobalConfig.getGeneratorCodeSavePath() + name.replaceAll("\\.", "/") + ".class"); - } - if (bytes != null) { - Class ret = defineClass(name, bytes, 0, bytes.length); - byteCodeMap.remove(name); - return ret; - } - - return super.findClass(name); - } -}