Class PluginContext<T>
- java.lang.Object
-
- com.google.gerrit.server.plugincontext.PluginContext<T>
-
public class PluginContext<T> extends Object
Context for invoking plugin extensions.Invoking a plugin extension through a PluginContext sets 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.
If possible plugin extensions should be invoked through:
PluginItemContext
for extensions fromDynamicItem
PluginSetContext
for extensions fromDynamicSet
PluginMapContext
for extensions fromDynamicMap
A plugin context can be manually opened by invoking the newTrace methods. This should only be needed if an extension throws multiple exceptions that need to be handled:
public interface Foo { void doFoo() throws Exception1, Exception2, Exception3; } ... for (Extension<Foo> fooExtension : fooDynamicMap) { try (TraceContext traceContext = PluginContext.newTrace(fooExtension)) { fooExtension.get().doFoo(); } }
This class hosts static methods with generic functionality to invoke plugin extensions with a trace context that are commonly used by
PluginItemContext
,PluginSetContext
andPluginMapContext
.The run* methods execute an extension but don't deliver a result back to the caller. Exceptions can be caught and logged.
The call* methods execute an extension and deliver a result back to the caller.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
PluginContext.CheckedExtensionFunction<T extends Extension<?>,R,X extends Exception>
static interface
PluginContext.CheckedExtensionImplFunction<T,R,X extends Exception>
static interface
PluginContext.ExtensionConsumer<T extends Extension<?>>
static interface
PluginContext.ExtensionFunction<T extends Extension<?>,R>
static interface
PluginContext.ExtensionImplConsumer<T>
static interface
PluginContext.ExtensionImplFunction<T,R>
static class
PluginContext.PluginMetrics
-
Constructor Summary
Constructors Constructor Description PluginContext()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> com.google.gerrit.server.logging.TraceContext
newTrace(DynamicItem<T> dynamicItem)
Opens a new trace context for invoking a plugin extension.static <T> com.google.gerrit.server.logging.TraceContext
newTrace(Extension<T> extension)
Opens a new trace context for invoking a plugin extension.
-
-
-
Method Detail
-
newTrace
public static <T> com.google.gerrit.server.logging.TraceContext newTrace(DynamicItem<T> dynamicItem)
Opens a new trace context for invoking a plugin extension.- Parameters:
dynamicItem
- dynamic item that holds the extension implementation that is being invoked from within the trace context- Returns:
- the created trace context
-
newTrace
public static <T> com.google.gerrit.server.logging.TraceContext newTrace(Extension<T> extension)
Opens a new trace context for invoking a plugin extension.- Parameters:
extension
- extension that is being invoked from within the trace context- Returns:
- the created trace context
-
-