public class PluginMapEntryContext<T>
extends java.lang.Object
DynamicMap
.
When the 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.
The run* methods execute the extension but don't deliver a result back to the caller. Exceptions can be caught and logged.
The call* methods execute the extension and deliver a result back to the caller.
Mapresults = new HashMap<>(); fooPluginMapEntryContext.run( extension -> results.put(extension.getExportName(), extension.get().getFoo());
Example if all exceptions, but one, should be caught and logged:
Mapresults = new HashMap<>(); try { fooPluginMapEntryContext.run( extension -> results.put(extension.getExportName(), extension.get().getFoo(), MyException.class); } catch (MyException e) { // handle the exception }
Example if return values should be handled:
Object result = fooPluginMapEntryContext.call(extension -> extension.get().getFoo());
Example if return values and a single exception should be handled:
Object result; try { result = fooPluginMapEntryContext.call(extension -> extension.get().getFoo(), MyException.class); } catch (MyException e) { // handle the exception }
Example if several exceptions should be handled:
for (ExtensionfooExtension : fooDynamicMap) { try (TraceContext traceContext = PluginContext.newTrace(fooExtension)) { fooExtension.get().doFoo(); } catch (MyException1 | MyException2 | MyException3 e) { // handle the exception } }
Modifier and Type | Method and Description |
---|---|
<R,X extends java.lang.Exception> |
call(PluginContext.CheckedExtensionFunction<Extension<T>,R,X> checkedExtensionFunction,
java.lang.Class<X> exceptionClass)
Calls the plugin extension and returns the result from the plugin extension call.
|
<R> R |
call(PluginContext.ExtensionFunction<Extension<T>,R> extensionFunction)
Calls the plugin extension and returns the result from the plugin extension call.
|
java.lang.String |
getExportName()
Returns the export name for which this map entry was registered.
|
java.lang.String |
getPluginName()
Returns the name of the plugin that registered this map entry.
|
void |
run(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer)
Invokes the plugin extension.
|
<X extends java.lang.Exception> |
run(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer,
java.lang.Class<X> exceptionClass)
Invokes the plugin extension.
|
public java.lang.String getPluginName()
public java.lang.String getExportName()
public void run(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer)
The consumer get the Extension
provided that should be invoked. The extension
provides access to the plugin name and the export name.
extensionConsumer
- consumer that invokes the extensionpublic <X extends java.lang.Exception> void run(PluginContext.ExtensionConsumer<Extension<T>> extensionConsumer, java.lang.Class<X> exceptionClass) throws X extends java.lang.Exception
The consumer get the Extension
provided that should be invoked. The extension
provides access to the plugin name and the export name.
extensionConsumer
- consumer that invokes the extensionexceptionClass
- type of the exceptions that should be thrownX
- expected exception from the plugin extensionX extends java.lang.Exception
public <R> R call(PluginContext.ExtensionFunction<Extension<T>,R> extensionFunction)
The consumer get the Extension
provided that should be invoked. The extension
provides access to the plugin name and the export name.
extensionFunction
- function that invokes the extensionpublic <R,X extends java.lang.Exception> R call(PluginContext.CheckedExtensionFunction<Extension<T>,R,X> checkedExtensionFunction, java.lang.Class<X> exceptionClass) throws X extends java.lang.Exception
The consumer get the Extension
provided that should be invoked. The extension
provides access to the plugin name and the export name.
checkedExtensionFunction
- function that invokes the extensionexceptionClass
- type of the exceptions that should be thrownX
- expected exception from the plugin extensionX extends java.lang.Exception