当前位置: 首页 > news >正文

佛山网站建设外包高端品牌鞋子排行榜前十名

佛山网站建设外包,高端品牌鞋子排行榜前十名,wordpress柒零贰,河北建设网站信息查询中心自定义classLoader实现加载外部jar, 以skywalking agent 类加载器为例子 整体思路 扩展findClass #xff0c;解决loadClass可以查找到扩展findResource#xff0c;解决getResources可以获取到资源 基本原理 ClassLoader loadClass的加载顺序 findLoadedClass 加载本地已经… 自定义classLoader实现加载外部jar, 以skywalking agent 类加载器为例子 整体思路 扩展findClass 解决loadClass可以查找到扩展findResource解决getResources可以获取到资源 基本原理 ClassLoader loadClass的加载顺序 findLoadedClass 加载本地已经加载过的class parent.loadClass 通过父类去加载class findClass 前面都没有加载到就通过findClass去搜索jar并加载class 扩展findClass 扩展findResource 扩展后AgentClassLoader.getDefault().getResources(“skywalking-plugin.def”); 就可以获取插件定义 完整源代码 AgentClassLoader /** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the License); you may not use this file except in compliance with* the License. You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an AS IS BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.**/package org.apache.skywalking.apm.agent.core.plugin.loader;import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.concurrent.locks.ReentrantLock; import java.util.jar.JarEntry; import java.util.jar.JarFile; import lombok.RequiredArgsConstructor; import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; import org.apache.skywalking.apm.agent.core.boot.PluginConfig; import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap;/*** The codeAgentClassLoader/code represents a classloader, which is in charge of finding plugins and interceptors.*/ public class AgentClassLoader extends ClassLoader {static {/** Try to solve the classloader dead lock. See https://github.com/apache/skywalking/pull/2016*/registerAsParallelCapable();}private static final ILog LOGGER LogManager.getLogger(AgentClassLoader.class);/*** The default class loader for the agent.*/private static AgentClassLoader DEFAULT_LOADER;private ListFile classpath;private ListJar allJars;private ReentrantLock jarScanLock new ReentrantLock();public static AgentClassLoader getDefault() {return DEFAULT_LOADER;}/*** Init the default class loader.** throws AgentPackageNotFoundException if agent package is not found.*/public static void initDefaultLoader() throws AgentPackageNotFoundException {if (DEFAULT_LOADER null) {synchronized (AgentClassLoader.class) {if (DEFAULT_LOADER null) {DEFAULT_LOADER new AgentClassLoader(PluginBootstrap.class.getClassLoader());}}}}public AgentClassLoader(ClassLoader parent) throws AgentPackageNotFoundException {super(parent);File agentDictionary AgentPackagePath.getPath();classpath new LinkedList();Config.Plugin.MOUNT.forEach(mountFolder - classpath.add(new File(agentDictionary, mountFolder)));}Overrideprotected Class? findClass(String name) throws ClassNotFoundException {ListJar allJars getAllJars();String path name.replace(., /).concat(.class);for (Jar jar : allJars) {JarEntry entry jar.jarFile.getJarEntry(path);if (entry null) {continue;}try {URL classFileUrl new URL(jar:file: jar.sourceFile.getAbsolutePath() !/ path);byte[] data;try (final BufferedInputStream is new BufferedInputStream(classFileUrl.openStream()); final ByteArrayOutputStream baos new ByteArrayOutputStream()) {int ch;while ((ch is.read()) ! -1) {baos.write(ch);}data baos.toByteArray();}return processLoadedClass(defineClass(name, data, 0, data.length));} catch (IOException e) {LOGGER.error(e, find class fail.);}}throw new ClassNotFoundException(Cant find name);}Overrideprotected URL findResource(String name) {ListJar allJars getAllJars();for (Jar jar : allJars) {JarEntry entry jar.jarFile.getJarEntry(name);if (entry ! null) {try {return new URL(jar:file: jar.sourceFile.getAbsolutePath() !/ name);} catch (MalformedURLException ignored) {}}}return null;}Overrideprotected EnumerationURL findResources(String name) throws IOException {ListURL allResources new LinkedList();ListJar allJars getAllJars();for (Jar jar : allJars) {JarEntry entry jar.jarFile.getJarEntry(name);if (entry ! null) {allResources.add(new URL(jar:file: jar.sourceFile.getAbsolutePath() !/ name));}}final IteratorURL iterator allResources.iterator();return new EnumerationURL() {Overridepublic boolean hasMoreElements() {return iterator.hasNext();}Overridepublic URL nextElement() {return iterator.next();}};}private Class? processLoadedClass(Class? loadedClass) {final PluginConfig pluginConfig loadedClass.getAnnotation(PluginConfig.class);if (pluginConfig ! null) {// Set up the plugin config when loaded by class loader at the first time.// Agent class loader just loaded limited classes in the plugin jar(s), so the cost of this// isAssignableFrom would be also very limited.SnifferConfigInitializer.initializeConfig(pluginConfig.root());}return loadedClass;}private ListJar getAllJars() {if (allJars null) {jarScanLock.lock();try {if (allJars null) {allJars doGetJars();}} finally {jarScanLock.unlock();}}return allJars;}private LinkedListJar doGetJars() {LinkedListJar jars new LinkedList();for (File path : classpath) {if (path.exists() path.isDirectory()) {String[] jarFileNames path.list((dir, name) - name.endsWith(.jar));for (String fileName : jarFileNames) {try {File file new File(path, fileName);Jar jar new Jar(new JarFile(file), file);jars.add(jar);LOGGER.info({} loaded., file.toString());} catch (IOException e) {LOGGER.error(e, {} jar file cant be resolved, fileName);}}}}return jars;}RequiredArgsConstructorprivate static class Jar {private final JarFile jarFile;private final File sourceFile;} }PluginResourcesResolver 获取skywalking-plugin.def插件定义 /** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the License); you may not use this file except in compliance with* the License. You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an AS IS BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.**/package org.apache.skywalking.apm.agent.core.plugin;import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.loader.AgentClassLoader;/*** Use the current classloader to read all plugin define file. The file must be named skywalking-plugin.def*/ public class PluginResourcesResolver {private static final ILog LOGGER LogManager.getLogger(PluginResourcesResolver.class);public ListURL getResources() {ListURL cfgUrlPaths new ArrayListURL();EnumerationURL urls;try {urls AgentClassLoader.getDefault().getResources(skywalking-plugin.def);while (urls.hasMoreElements()) {URL pluginUrl urls.nextElement();cfgUrlPaths.add(pluginUrl);LOGGER.info(find skywalking plugin define in {}, pluginUrl);}return cfgUrlPaths;} catch (IOException e) {LOGGER.error(read resources failure., e);}return null;} }
http://www.dnsts.com.cn/news/52865.html

相关文章:

  • 做淘宝客网站能接广告吗公司网站建设方案ppt
  • 门户类网站图片wordpress 用户注册插件
  • 网站建设和使用现状wordpress编辑邮箱内容
  • 网站建设信息表wordpress设置多站点
  • 南通制作企业网站交通运输部: 优化交通运输领域防控
  • 台州新农村建设网站哪些网站可以上传自己做的视频
  • 西部数码网站备份东莞最好的网站建设价格低
  • 电子商务网站开发教程论文6网站建设横幅
  • 有什么网站可以接单做兼职的大连优化排名推广
  • 墙绘做网站哪家好自己怎么设计公司标志
  • 学校网站管理系统基础做网站
  • 网站开发有哪些参考文献高校网站建设招标公告
  • 用html做女装网站网站建设需要哪种人才
  • 四川省住房与城乡建设 厅网站绿色wordpress主题模板下载
  • 网站不能写入php文件免费行情网站app下载大全
  • 如何提高网站收录量惠东网站设计
  • 做网站必要吗安徽六安金寨县
  • 网站建设和程序开发哪个好海口建站软件
  • 中卫网站推广优化公司做商城购物网站
  • 进贤网站建设网站建设尾款放在什么科目里
  • 给公司建网站 深圳唐山 网站建设
  • 网站的建设方式有哪些网站备案 几年
  • 手机版网站设计风格宜昌微网站建设
  • 网站广告源码免费表白网页在线生成制作
  • 哪类小网站容易做鹿泉建设网站
  • 三网合一网站建设合同微信小程序怎么上架商品
  • 做明星网站打广告购物网站怎么做推广
  • 做科学小制作的视频网站找装修公司的网站
  • 如何seo网站外贸如何推广公司网站
  • 长春seo技术seo关键词优化排名外包