use of org.apache.logging.log4j.plugins.processor.PluginService in project logging-log4j2 by apache.
the class PluginRegistry method loadPlugins.
/**
* Load plugins from a specific ClassLoader.
* @param classLoader The ClassLoader.
* @param map The Map of the list of plugin types organized by category.
* @since 3.0
*/
public void loadPlugins(ClassLoader classLoader, Map<String, List<PluginType<?>>> map) {
final long startTime = System.nanoTime();
final ServiceLoader<PluginService> serviceLoader = ServiceLoader.load(PluginService.class, classLoader);
int pluginCount = 0;
for (final PluginService pluginService : serviceLoader) {
PluginEntry[] entries = pluginService.getEntries();
for (PluginEntry entry : entries) {
final PluginType<?> type = new PluginType<>(entry, classLoader);
String category = entry.getCategory().toLowerCase();
if (!map.containsKey(category)) {
map.put(category, new ArrayList<>());
}
List<PluginType<?>> list = map.get(category);
list.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(classLoader);
return sb.toString();
});
}
use of org.apache.logging.log4j.plugins.processor.PluginService in project logging-log4j2 by apache.
the class Activator method loadPlugins.
private void loadPlugins(final BundleContext bundleContext) {
try {
final Collection<ServiceReference<PluginService>> serviceReferences = bundleContext.getServiceReferences(PluginService.class, null);
for (final ServiceReference<PluginService> serviceReference : serviceReferences) {
final PluginService pluginService = bundleContext.getService(serviceReference);
PluginRegistry.getInstance().loadFromBundle(pluginService.getCategories(), bundleContext.getBundle().getBundleId());
}
} catch (final InvalidSyntaxException ex) {
LOGGER.error("Error accessing Plugins", ex);
}
}
Aggregations