Class PluginMapContext<T>
- All Implemented Interfaces:
- Iterable<PluginMapEntryContext<T>>
DynamicMap.
 When a plugin extension is invoked a logging tag with the plugin name is set. This way any errors that are triggered by the plugin extension (even if they happen in Gerrit code which is called by the plugin extension) can be easily attributed to the plugin.
Example if all exceptions should be caught and logged:
 Map<String, Object> results = new HashMap<>();
 fooPluginMapContext.runEach(
     extension -> results.put(extension.getExportName(), extension.get().getFoo());
 Example if all exceptions, but one, should be caught and logged:
 Map<String, Object> results = new HashMap<>();
 try {
   fooPluginMapContext.runEach(
       extension -> results.put(extension.getExportName(), extension.get().getFoo(),
       MyException.class);
 } catch (MyException e) {
   // handle the exception
 }
 Example if return values should be handled:
 Map<String, Object> results = new HashMap<>();
 for (PluginMapEntryContext<Foo> c : fooPluginMapContext) {
   if (c.call(extension -> extension.get().handles(x))) {
     c.run(extension -> results.put(extension.getExportName(), extension.get().getFoo());
   }
 }
 Example if return values and a single exception should be handled:
 Map<String, Object> results = new HashMap<>();
 try {
   for (PluginMapEntryContext<Foo> c : fooPluginMapContext) {
     if (c.call(extension -> extension.handles(x), MyException.class)) {
       c.run(extension -> results.put(extension.getExportName(), extension.get().getFoo(),
           MyException.class);
     }
   }
 } catch (MyException e) {
   // handle the exception
 }
 Example if several exceptions should be handled:
 for (Extension<Foo> fooExtension : fooDynamicMap) {
   try (TraceContext traceContext = PluginContext.newTrace(fooExtension)) {
     fooExtension.get().doFoo();
   } catch (MyException1 | MyException2 | MyException3 e) {
     // handle the exception
   }
 }
 - 
Constructor SummaryConstructorsConstructorDescriptionPluginMapContext(DynamicMap<T> dynamicMap, PluginContext.PluginMetrics pluginMetrics) 
- 
Method SummaryModifier and TypeMethodDescriptionbooleanisEmpty()Checks if no implementations for this extension point have been registered.iterator()Iterator that provides contexts for invoking the extensions in this map.plugins()Returns a sorted list of the plugins that have registered implementations for this extension point.voidrunEach(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer) Invokes each extension in the map.<X extends Exception>
 voidrunEach(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer, Class<X> exceptionClass) Invokes each extension in the map.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Constructor Details- 
PluginMapContext@Inject public PluginMapContext(DynamicMap<T> dynamicMap, PluginContext.PluginMetrics pluginMetrics) 
 
- 
- 
Method Details- 
iteratorIterator that provides contexts for invoking the extensions in this map.This is useful if: - invoking of each extension returns a result that should be handled
- a sequence of invocations should be done on each extension
 
- 
isEmptypublic boolean isEmpty()Checks if no implementations for this extension point have been registered.- Returns:
- trueif no implementations for this extension point have been registered, otherwise- false
 
- 
pluginsReturns a sorted list of the plugins that have registered implementations for this extension point.- Returns:
- sorted list of the plugins that have registered implementations for this extension point
 
- 
runEachInvokes each extension in the map. All exceptions from the plugin extensions are caught and logged.The consumer get the Extensionprovided that should be invoked. The extension provides access to the plugin name and the export name.All extension in the map are invoked, even if invoking some of the extensions failed. - Parameters:
- extensionConsumer- consumer that invokes the extension
 
- 
runEachpublic <X extends Exception> void runEach(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer, Class<X> exceptionClass) throws X Invokes each extension in the map. All exceptions from the plugin extensions except exceptions of the specified type are caught and logged.The consumer get the Extensionprovided that should be invoked. The extension provides access to the plugin name and the export name.All extension in the map are invoked, even if invoking some of the extensions failed. - Parameters:
- extensionConsumer- consumer that invokes the extension
- exceptionClass- type of the exceptions that should be thrown
- Throws:
- X- expected exception from the plugin extension
 
 
-