import org.apache.logging.log4j.core.config.plugins.Plugin; //导入依赖的package包/类

/**

* @since 2.1

*/

public Map>> loadFromPackage(final String pkg) {

if (Strings.isBlank(pkg)) {

// happens when splitting an empty string

return Collections.emptyMap();

}

Map>> existing = pluginsByCategoryByPackage.get(pkg);

if (existing != null) {

// already loaded this package

return existing;

}

final long startTime = System.nanoTime();

final ResolverUtil resolver = new ResolverUtil();

final ClassLoader classLoader = Loader.getClassLoader();

if (classLoader != null) {

resolver.setClassLoader(classLoader);

}

resolver.findInPackage(new PluginTest(), pkg);

final Map>> newPluginsByCategory = new HashMap<>();

for (final Class> clazz : resolver.getClasses()) {

final Plugin plugin = clazz.getAnnotation(Plugin.class);

final String categoryLowerCase = plugin.category().toLowerCase();

List> list = newPluginsByCategory.get(categoryLowerCase);

if (list == null) {

newPluginsByCategory.put(categoryLowerCase, list = new ArrayList<>());

}

final PluginEntry mainEntry = new PluginEntry();

final String mainElementName = plugin.elementType().equals(

Plugin.EMPTY) ? plugin.name() : plugin.elementType();

mainEntry.setKey(plugin.name().toLowerCase());

mainEntry.setName(plugin.name());

mainEntry.setCategory(plugin.category());

mainEntry.setClassName(clazz.getName());

mainEntry.setPrintable(plugin.printObject());

mainEntry.setDefer(plugin.deferChildren());

final PluginType> mainType = new PluginType<>(mainEntry, clazz, mainElementName);

list.add(mainType);

final PluginAliases pluginAliases = clazz.getAnnotation(PluginAliases.class);

if (pluginAliases != null) {

for (final String alias : pluginAliases.value()) {

final PluginEntry aliasEntry = new PluginEntry();

final String aliasElementName = plugin.elementType().equals(

Plugin.EMPTY) ? alias.trim() : plugin.elementType();

aliasEntry.setKey(alias.trim().toLowerCase());

aliasEntry.setName(plugin.name());

aliasEntry.setCategory(plugin.category());

aliasEntry.setClassName(clazz.getName());

aliasEntry.setPrintable(plugin.printObject());

aliasEntry.setDefer(plugin.deferChildren());

final PluginType> aliasType = new PluginType<>(aliasEntry, clazz, aliasElementName);

list.add(aliasType);

}

}

}

final long endTime = System.nanoTime();

final DecimalFormat numFormat = new DecimalFormat("#0.000000");

final double seconds = (endTime - startTime) * 1e-9;

LOGGER.debug("Took {} seconds to load {} plugins from package {}",

numFormat.format(seconds), resolver.getClasses().size(), pkg);

// Note multiple threads could be calling this method concurrently. Both will do the work,

// but only one will be allowed to store the result in the outer map.

// Return the inner map produced by whichever thread won the race, so all callers will get the same result.

existing = pluginsByCategoryByPackage.putIfAbsent(pkg, newPluginsByCategory);

if (existing != null) {

return existing;

}

return newPluginsByCategory;

}

java plugin_Java Plugin类代码示例相关推荐

  1. java dataconvert_Java DateConverter类代码示例

    import org.apache.commons.beanutils.converters.DateConverter; //导入依赖的package包/类 /** * Register array ...

  2. java parseexception_Java ParseException类代码示例

    import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException; //导入依赖的package包/类 @Overri ...

  3. java link_Java Link类代码示例

    import org.nodes.Link; //导入依赖的package包/类 public static double sizeBetaCopying(DGraph graph, DGraph s ...

  4. java bar_Java Bar类代码示例

    import com.db.chart.model.Bar; //导入依赖的package包/类 @Override protected void onCreate(Bundle savedInsta ...

  5. java backoff_Java BackOff类代码示例

    import org.apache.beam.sdk.util.BackOff; //导入依赖的package包/类 /** * Writes a batch of mutations to Clou ...

  6. java widget_Java FavoritesWidget类代码示例

    import com.google.gwt.sample.dynatablerf.client.widgets.FavoritesWidget; //导入依赖的package包/类 /** * Thi ...

  7. java direction_Java Direction类代码示例

    import android.support.test.uiautomator.Direction; //导入依赖的package包/类 /** * Navigates through the foc ...

  8. java jsonresult_Java JsonResult类代码示例

    import eu.socialsensor.framework.client.search.visual.JsonResultSet.JsonResult; //导入依赖的package包/类 @O ...

  9. postgresql java demo_Java PostgreSQL9Dialect类代码示例

    import org.hibernate.dialect.PostgreSQL9Dialect; //导入依赖的package包/类 private void addDialects(Strategy ...

最新文章

  1. 为何 Windows 10X 无法延续 Windows 的成功?
  2. 深入理解 Spring 之源码剖析IOC
  3. gitlab将分支代码合并到master上
  4. 并行计算(一)——并行计算机系统及结构模型
  5. 3分钟快速理解什么是Docker容器
  6. 85. Maximal Rectangle 由1拼出的最大矩形
  7. cgi一键还原 linux分区,用一键恢复CGI工具备份还原分区和硬盘使用图文教程
  8. EPLAN史上最全部件库,官网下载,部件宏,EDZ格式,239G,导入后一劳永逸
  9. 代购源码,淘宝代购系统源码,代购程序,代购系统源码PHP前端源码参数说明
  10. Python自动化办公:word文件操作教程
  11. ASP.net 简单登录界面
  12. DirectX函数归纳总结
  13. 服务器接收 App Store 苹果商店内购项目IAP的退款通知
  14. cmd中怎么进mysql
  15. 方维互动直播系统(美女、游戏、会议、在线教育、体育、赛事直播系统)
  16. __kfifo_put和__kfifo_get
  17. 英文歌曲:God is a girl(上帝是女孩)
  18. 网站常用的五种布局方案
  19. pytorch下载慢的问题解决方法
  20. 【附源码】计算机毕业设计SSM实验室安全准入考试系统

热门文章

  1. linux电机驱动程序,基于Linux系统的HHARM9电机驱动程序设计
  2. APT60DQ60BG ASEMI超快软恢复整流二极管
  3. Linux常见目录的全称
  4. 计算机为什么检测不到u盘启动项,BIOS设置启动U盘为第一启动项却检测不到的解决办法【详解】...
  5. 【sketchup 2021】草图大师的高级工具使用1【不透明度高级使用、填充材质高级使用】
  6. 2022-2028全球与中国模板系统(SOM)市场现状及未来发展趋势
  7. Nick认为的SDN三阶段
  8. flutter项目:启动名称生成器(代码解析)
  9. SQL必知必会-笔记(完善版):第1课
  10. 智能安卓电视USB声卡解码器音量限制,只能同轴数字音频输出+遥控音量