Search in sources :

Example 1 with PluginCache

use of org.apache.logging.log4j.plugins.processor.PluginCache in project logging-log4j2 by apache.

the class PluginRegistry method decodeCacheFiles.

private Map<String, List<PluginType<?>>> decodeCacheFiles(final ClassLoader loader) {
    final long startTime = System.nanoTime();
    final PluginCache cache = new PluginCache();
    try {
        final Enumeration<URL> resources = loader.getResources(PluginManager.PLUGIN_CACHE_FILE);
        if (resources == null) {
            LOGGER.info("Plugin preloads not available from class loader {}", loader);
        } else {
            cache.loadCacheFiles(resources);
        }
    } catch (final IOException ioe) {
        LOGGER.warn("Unable to preload plugins", ioe);
    }
    final Map<String, List<PluginType<?>>> newPluginsByCategory = new HashMap<>();
    int pluginCount = 0;
    for (final Map.Entry<String, Map<String, PluginEntry>> outer : cache.getAllCategories().entrySet()) {
        final String categoryLowerCase = outer.getKey();
        final List<PluginType<?>> types = new ArrayList<>(outer.getValue().size());
        newPluginsByCategory.put(categoryLowerCase, types);
        for (final Map.Entry<String, PluginEntry> inner : outer.getValue().entrySet()) {
            final PluginEntry entry = inner.getValue();
            final String className = entry.getClassName();
            final PluginType<?> type = new PluginType<>(entry, loader);
            types.add(type);
            ++pluginCount;
        }
    }
    final int numPlugins = pluginCount;
    LOGGER.debug(() -> {
        final long endTime = System.nanoTime();
        StringBuilder sb = new StringBuilder("Took ");
        final DecimalFormat numFormat = new DecimalFormat("#0.000000");
        sb.append(numFormat.format((endTime - startTime) * 1e-9));
        sb.append(" seconds to load ").append(numPlugins);
        sb.append(" plugins from ").append(loader);
        return sb.toString();
    });
    return newPluginsByCategory;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) PluginEntry(org.apache.logging.log4j.plugins.processor.PluginEntry) IOException(java.io.IOException) URL(java.net.URL) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PluginCache(org.apache.logging.log4j.plugins.processor.PluginCache) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 PluginCache (org.apache.logging.log4j.plugins.processor.PluginCache)1 PluginEntry (org.apache.logging.log4j.plugins.processor.PluginEntry)1