public class PluginSetEntryContext<T> extends Object
DynamicSet
.
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.
Example if all exceptions should be caught and logged:
fooPluginSetEntryContext.run(foo -> foo.doFoo());
Example if all exceptions, but one, should be caught and logged:
try { fooPluginSetEntryContext.run(foo -> foo.doFoo(), MyException.class); } catch (MyException e) { // handle the exception }
Example if return values should be handled:
Object result = fooPluginSetEntryContext.call(foo -> foo.getFoo());
Example if return values and a single exception should be handled:
Object result; try { result = fooPluginSetEntryContext.call(foo -> foo.getFoo(), MyException.class); } catch (MyException e) { // handle the exception }
Example if several exceptions should be handled:
for (ExtensionfooExtension : fooDynamicSet.entries()) { 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 Exception> |
call(PluginContext.CheckedExtensionImplFunction<T,R,X> checkedExtensionImplFunction,
Class<X> exceptionClass)
Calls the plugin extension and returns the result from the plugin extension call.
|
<R> R |
call(PluginContext.ExtensionImplFunction<T,R> extensionImplFunction)
Calls the plugin extension and returns the result from the plugin extension call.
|
T |
get()
Returns the implementation of this extension.
|
String |
getPluginName()
Returns the name of the plugin that registered this extension.
|
void |
run(PluginContext.ExtensionImplConsumer<T> extensionImplConsumer)
Invokes the plugin extension.
|
<X extends Exception> |
run(PluginContext.ExtensionImplConsumer<T> extensionImplConsumer,
Class<X> exceptionClass)
Invokes the plugin extension.
|
public String getPluginName()
public T get()
Should only be used in exceptional cases to get direct access to the extension
implementation. If possible the extension should be invoked through run(PluginContext.ExtensionImplConsumer)
, run(PluginContext.ExtensionImplConsumer,
java.lang.Class)
, call(PluginContext.ExtensionImplFunction)
and call(PluginContext.CheckedExtensionImplFunction, java.lang.Class)
.
public void run(PluginContext.ExtensionImplConsumer<T> extensionImplConsumer)
The consumer gets the extension implementation provided that should be invoked.
extensionImplConsumer
- consumer that invokes the extensionpublic <X extends Exception> void run(PluginContext.ExtensionImplConsumer<T> extensionImplConsumer, Class<X> exceptionClass) throws X extends Exception
The consumer gets the extension implementation provided that should be invoked.
extensionImplConsumer
- consumer that invokes the extensionexceptionClass
- type of the exceptions that should be thrownX
- expected exception from the plugin extensionX extends Exception
public <R> R call(PluginContext.ExtensionImplFunction<T,R> extensionImplFunction)
The function gets the extension point provided that should be invoked.
extensionImplFunction
- function that invokes the extensionpublic <R,X extends Exception> R call(PluginContext.CheckedExtensionImplFunction<T,R,X> checkedExtensionImplFunction, Class<X> exceptionClass) throws X extends Exception
The function gets the extension implementation provided that should be invoked.
checkedExtensionImplFunction
- function that invokes the extensionexceptionClass
- type of the exceptions that should be thrownX
- expected exception from the plugin extensionX extends Exception