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

宝鸡网站建设公司电话seo能从搜索引擎中获得更多的

宝鸡网站建设公司电话,seo能从搜索引擎中获得更多的,9个做简历的网站,贵阳网站建设哪家好方舟自定义classLoader实现加载外部jar, 以skywalking agent 类加载器为例子 整体思路 扩展findClass ,解决loadClass可以查找到扩展findResource,解决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 <code>AgentClassLoader</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 List<File> classpath;private List<Jar> 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 {List<Jar> 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("Can't find " + name);}@Overrideprotected URL findResource(String name) {List<Jar> 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 Enumeration<URL> findResources(String name) throws IOException {List<URL> allResources = new LinkedList<>();List<Jar> 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 Iterator<URL> iterator = allResources.iterator();return new Enumeration<URL>() {@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 List<Jar> getAllJars() {if (allJars == null) {jarScanLock.lock();try {if (allJars == null) {allJars = doGetJars();}} finally {jarScanLock.unlock();}}return allJars;}private LinkedList<Jar> doGetJars() {LinkedList<Jar> 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 can't 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 List<URL> getResources() {List<URL> cfgUrlPaths = new ArrayList<URL>();Enumeration<URL> 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.zhongyajixie.com/news/42198.html

相关文章:

  • 阿里巴巴如何做网站app拉新推广怎么做
  • 专业做室内设计的网站有哪些企业自建网站
  • 长沙商城网站国内做网站的公司
  • 网站域名验证搜索引擎营销分类
  • wordpress自带主题下载徐州百度seo排名
  • 象山县城乡建设局网站seo网络搜索引擎优化
  • wordpress做淘客网站seo主要优化哪些
  • 软件公司做网站常见的搜索引擎有哪些
  • 做带字头像的网站宁波seo托管公司
  • 糕点网站策划书怎样做一个网页
  • 站点创建seo实战密码第三版
  • 网站流量真难做网络推广优化网站
  • 自己做网站卖货多少钱网络广告策划的内容
  • 怀柔区建设委员会网站一起来看在线观看免费
  • 网站备案号如何获得清理大师
  • 公司做网站需要服务器吗现代网络营销的方式
  • dede网站地图文章变量安徽百度推广怎么做
  • 有没有教做黄色网站行业关键词查询
  • php婚庆网站源码全网最好的推广平台
  • seo网站页面诊断群排名优化软件官网
  • 外贸网站页面用什么做最好网络营销个人总结
  • 厦门 网站优化微信广告朋友圈投放
  • 网站建设需要什么教材各网站收录
  • html网页搭建金华seo扣费
  • 招聘网站建设初衷360关键词排名百度
  • 网站app搭建百度网页版链接地址
  • 做网站架构需要注意什么十大免费软文推广平台
  • 广州品牌seo网站推广建设企业网站多少钱
  • 济南网站制作哪家专业seo与sem的区别与联系
  • 晋江市住房和城乡建设网站西安网络推广公司网络推广