Repository navigation
Expand file tree
/
Copy pathPluginRunner.java
More file actions
558 lines (509 loc) · 27.4 KB
/
Copy pathPluginRunner.java
File metadata and controls
558 lines (509 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.lambda.durable.plugin;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.lambda.durable.util.ExceptionHelper;
/**
* Dispatches the lifecycle hooks of a single Lambda invocation to that invocation's plugin instances.
*
* <p>A runner is created per invocation from the configured {@link DurableExecutionPluginFactory factories} and holds
* no plugin instances until {@link #onInvocationStart(InvocationInfo)} materializes and starts each plugin in
* configured order, from the very {@link InvocationInfo} the first hook then receives. {@link #releasePlugins()} drops
* them when the invocation returns, so a plugin instance is never shared between invocations and never needs to key its
* state by execution ARN.
*
* <p>Event hooks are fire-and-forget: each plugin is called in order, non-fatal failures are contained. A factory with
* a non-fatal failure or returns {@code null} is contained the same way — the plugin is skipped for the invocation.
* Containment covers every non-fatal throwable, not only {@link Exception}, because a plugin built against a different
* SDK version, one missing an optional dependency, and one running with assertions enabled all fail with an
* {@code Error}. It stops short of two cases, which keep propagating: the errors that report the JVM itself failing,
* and the {@code ThreadDeath} that reports the thread running the plugin has already been terminated.
*
* <p>{@code onInvocationEnd} runs on the root handler thread after body unwinding, operation/checkpoint draining, and
* output preparation. The SDK awaits it before returning, so plugins can flush data before Lambda freezes.
*/
public class PluginRunner {
private static final Logger logger = LoggerFactory.getLogger(PluginRunner.class);
private static final UserFunctionHooks EMPTY_USER_FUNCTION_HOOKS = new UserFunctionHooks(List.of(), fatal -> {});
private final List<DurableExecutionPluginFactory> pluginFactories;
private final Consumer<Error> operationFatalObserver;
/**
* This invocation's plugin instances. Written once on the thread that fires {@code onInvocationStart}, read from
* the user, checkpoint, and operation threads that fire the later hooks — volatile for that publication.
*/
private volatile List<DurableExecutionPlugin> plugins = List.of();
public PluginRunner(List<DurableExecutionPluginFactory> pluginFactories) {
this(pluginFactories, fatal -> {});
}
/** Reports fatal operation and invocation-end hooks to their invocation before rethrowing. */
public PluginRunner(List<DurableExecutionPluginFactory> pluginFactories, Consumer<Error> operationFatalObserver) {
this.operationFatalObserver = operationFatalObserver;
this.pluginFactories = pluginFactories != null ? List.copyOf(pluginFactories) : Collections.emptyList();
validateExclusiveGroups(this.pluginFactories);
}
/** Validates configured factory metadata without creating invocation-owned plugins or spans. */
public static void validateExclusiveGroups(List<DurableExecutionPluginFactory> factories) {
var groups = new HashMap<String, DurableExecutionPluginFactory>();
for (var factory : factories) {
var group = factory.getExclusiveGroup();
if (group == null) continue;
var previous = groups.putIfAbsent(group, factory);
if (previous != null)
throw new IllegalArgumentException("Conflicting plugin factories " + previous + " and " + factory
+ " in exclusive group '" + group + "'. Configure only one plugin from this group.");
}
}
/** Returns a runner with no plugin factories, which does nothing. */
public static PluginRunner noOp() {
return new PluginRunner(Collections.emptyList());
}
/** Returns true if no plugin factories are registered. */
public boolean isEmpty() {
return pluginFactories.isEmpty();
}
// ─── Per-invocation lifetime ─────────────────────────────────────────
/**
* Creates this invocation's plugin instances, one per registered factory.
*
* <p>Called from {@link #onInvocationStart(InvocationInfo)}. Each start hook runs before constructing the next
* plugin, preserving startup context installed by earlier registrations. Factories that fail non-fatally or return
* null are logged and skipped. Fatal causes propagate, including through completion/future wrappers.
*
* <p>Every non-fatal throwable is contained, not just {@link Exception}. The contract says a non-fatal factory
* failure is skipped and never disrupts the execution, and a throwable that escapes here fails an execution the
* plugin was only observing. Narrowing the catch to a list of types would leave that promise conditional on the
* list being complete, and it was not: a provider JAR compiled against an earlier version of
* {@link DurableExecutionPluginFactory} throws {@link AbstractMethodError}, a provider whose optional dependency is
* missing from the deployment package throws {@link NoClassDefFoundError}, a provider running with assertions
* enabled throws {@link AssertionError}, and a provider that loads its own exporter back ends through
* {@link java.util.ServiceLoader} throws {@link java.util.ServiceConfigurationError}. Only the first two are
* {@link LinkageError} and none is an {@link Exception}. Catching {@code Throwable} and rethrowing only the fatal
* cases makes the promise unconditional. See {@link #contain} for which cases stay fatal.
*/
private void createPlugins(InvocationInfo info) {
var created = new ArrayList<DurableExecutionPlugin>(pluginFactories.size());
try {
for (var factory : pluginFactories) {
var plugin = createPlugin(factory, info);
if (plugin == null) continue;
created.add(plugin);
runPlugin(plugin, p -> p.onInvocationStart(info));
}
} finally {
// Even a fatal constructor/start failure must leave already-created instances available for finalization.
// Publishing after startup also makes state assigned by start hooks visible to later SDK threads.
this.plugins = List.copyOf(created);
}
}
private static DurableExecutionPlugin createPlugin(DurableExecutionPluginFactory factory, InvocationInfo info) {
try {
var plugin = factory.createPlugin(info);
if (plugin == null)
logger.warn("Plugin factory {} returned null; skipping it for this invocation", factory);
return plugin;
} catch (Throwable failure) {
contain(failure, "Plugin factory failed; skipping it for this invocation");
return null;
}
}
/**
* Drops invocation-level plugin references when the invocation returns. A started operation retains only its
* matching hook recipients until its owner unwinds; these recipients are never reused by another invocation.
*
* <p>No containment here: this only replaces the field, and calls nothing on the plugins it drops. There is no
* {@code close()} in the plugin contract, so releasing cannot run plugin code and cannot fail.
*/
public void releasePlugins() {
this.plugins = List.of();
}
/**
* Collects supported metadata in configured order on the caller's thread. First non-null member wins; matching
* later values are harmless. Ordinary plugin/invalid-result failures and linkage errors are logged and skipped,
* matching the event hooks' isolation policy; other Errors continue to propagate. The core calls this while
* creating a new invoke START checkpoint, not while replaying an existing operation.
*/
public PropagationMetadata providePropagationMetadata(PropagationInput input) {
requireNonNull(input, "input");
String selected = null;
String owner = null;
var conflicts = 0;
for (var index = 0; index < plugins.size(); index++) {
var plugin = plugins.get(index);
var identity = plugin.getClass().getName() + "[" + index + "]";
try {
var candidate = propagationHeader(plugin, input);
if (candidate == null) continue;
if (selected == null) {
selected = candidate;
owner = identity;
} else if (!selected.equals(candidate)) {
warnPropagation(
"Conflicting xAmznTraceId from plugin {}; retaining plugin {} (conflict count: {})",
identity,
owner,
++conflicts);
}
} catch (Exception | LinkageError failure) {
warnPropagation("Propagation metadata from plugin {} failed; skipping contribution", identity, failure);
}
}
return selected != null ? new PropagationMetadata(selected) : null;
}
private static String propagationHeader(DurableExecutionPlugin plugin, PropagationInput input) {
var metadata = plugin.providePropagationMetadata(input);
var header = metadata != null ? metadata.xAmznTraceId() : null;
if (header != null && header.isBlank()) {
throw new IllegalArgumentException("xAmznTraceId must not be blank");
}
return header;
}
private static void warnPropagation(String message, Object... arguments) {
try {
logger.warn(message, arguments);
} catch (RuntimeException ignored) {
// A failed logging backend cannot change optional metadata collection or the handler's result.
}
}
// ─── Event hooks ─────────────────────────────────────────────────────
/**
* Calls a void hook on all of this invocation's plugins, swallowing any non-fatal throwable.
*
* <p>Containment here follows the same rule as {@link #createPlugins}, because the fire-and-forget contract makes
* no distinction between the two boundaries. A plugin fails a hook with the same shapes a factory fails with, and
* one plugin's failure must not stop the remaining plugins from receiving the hook or fail the execution. See
* {@link #contain} for which cases stay fatal.
*/
private void run(Consumer<DurableExecutionPlugin> hook) {
for (var plugin : plugins) {
runPlugin(plugin, hook);
}
}
private static void runPlugin(DurableExecutionPlugin plugin, Consumer<DurableExecutionPlugin> hook) {
try {
hook.accept(plugin);
} catch (Throwable failure) {
contain(failure, "Plugin hook failed");
}
}
/**
* Logs a throwable that plugin code produced, or rethrows it if it is fatal.
*
* <p>A {@link VirtualMachineError} is the JVM reporting that it can no longer run correctly, which covers
* {@link OutOfMemoryError}, {@link StackOverflowError}, {@link InternalError} and {@link UnknownError}. That is not
* a plugin defect, and the process cannot be assumed able to continue past it. Logging it as a contained plugin
* failure would therefore hide a condition the caller has to see, so it is rethrown unchanged. The rule names the
* supertype rather than the four subclasses so that a subclass added later is fatal without an edit here.
*
* <p>{@code ThreadDeath} is fatal for a different reason. It is not a report of a failure but a thread termination
* that has already begun: {@code Thread.stop()} delivers it by throwing it into the target thread, which unwinds
* that thread's stack from wherever it stood and releases the monitors it held over state it had only half updated.
* The threads that create plugins and fire hooks are SDK threads that carry SDK and user work after the plugin
* returns. Containing the {@code ThreadDeath} would therefore return one of those threads to that work with its
* invariants already broken and the termination it was sent silently dropped. It is rethrown unchanged so the
* termination completes.
*
* <p>{@code Thread.stop()} throws {@link UnsupportedOperationException} on JDK 20 and later, so the JVM cannot
* deliver a {@code ThreadDeath} on those runtimes. It can deliver one on JDK 17, and {@code maven.compiler.source}
* is 17, so the rethrow is reachable on a runtime this SDK supports. A {@code ThreadDeath} that plugin code
* constructs and throws itself is rethrown on every runtime; the boundary cannot distinguish it from a delivered
* one, and treating the ambiguous case as fatal is the safe direction.
*
* <p>{@code ThreadDeath} is deprecated for removal since JDK 20, so naming it emits a removal warning when this
* class is compiled on a JDK 20 or later compiler. The {@code @SuppressWarnings("removal")} below is scoped to this
* method rather than the class so it cannot mask a removal warning that appears elsewhere in {@code PluginRunner}.
*
* <p>An {@link InterruptedException} is contained like any other non-fatal throwable, and the interrupt status is
* not restored. Three facts decide it. The thread that creates plugins and fires {@code onInvocationStart} is the
* handler thread — the hook runs there on purpose, so a plugin can set a {@code ThreadLocal} or an MDC key the
* handler's own logging then reads — so setting the flag there leaves the handler's next blocking call to fail with
* an {@code InterruptedException} that no user code asked for, which is the containment contract broken by the
* boundary meant to enforce it. A thrown {@code InterruptedException} is also no proof that the thread was
* interrupted: no hook and no factory method declares a checked exception, so the only way one arrives is plugin
* code rethrowing it undeclared, and plugin code can construct one and throw it with the interrupt status clear.
* And no SDK code interrupts these threads or reads their interrupt status, so restoring the flag serves no waiting
* reader. The interrupt is reported the way every other contained plugin failure is, as a logged warning naming the
* plugin boundary that produced it.
*/
@SuppressWarnings("removal") // ThreadDeath is deprecated for removal since JDK 20; see the javadoc above.
private static void contain(Throwable t, String message) {
var cause = ExceptionHelper.unwrapAsyncFailure(t);
if (cause instanceof VirtualMachineError fatal) {
throw fatal;
}
if (cause instanceof ThreadDeath fatal) {
throw fatal;
}
try {
logger.warn(message, t);
} catch (Throwable loggingFailure) {
rethrowDiagnosticFatal(loggingFailure);
try {
logger.warn(
"{} ({}; exception details unavailable)",
message,
t.getClass().getName());
} catch (Throwable fallbackFailure) {
rethrowDiagnosticFatal(fallbackFailure);
}
}
}
@SuppressWarnings("removal")
private static void rethrowDiagnosticFatal(Throwable failure) {
var cause = ExceptionHelper.unwrapAsyncFailure(failure);
if (cause instanceof VirtualMachineError fatal) throw fatal;
if (cause instanceof ThreadDeath fatal) throw fatal;
}
/**
* Called at the start of each invocation. Materializes this invocation's plugin instances from the registered
* factories, then dispatches the hook to them with the same {@link InvocationInfo} the factories received.
*/
/** Runs the root handler with optional plugin scopes, closing them on the same thread in reverse order. */
public <T> T runHandler(Supplier<T> handler) {
return runHandler(handler, () -> {});
}
/** Runs the handler and notifies the invocation when a scope requires same-thread finalization. */
public <T> T runHandler(Supplier<T> handler, Runnable onScopeOpened) {
return runHandler(handler, onScopeOpened, fatal -> {});
}
/** Reports fatal errors from scope callbacks; retains the existing standalone runner body policy. */
public <T> T runHandler(Supplier<T> handler, Runnable onScopeOpened, Consumer<Error> onScopeFatal) {
return runHandler(handler, onScopeOpened, onScopeFatal, null);
}
/**
* Publishes an existing-classifier body fatal before owned cleanup only if the invocation still accepts it. The
* publisher returns the winning fatal, or null when earlier invocation control already won. A null publisher
* retains the standalone body path without classifying its failures.
*/
@SuppressWarnings("removal")
public <T> T runHandler(
Supplier<T> handler,
Runnable onScopeOpened,
Consumer<Error> onScopeFatal,
Function<Error, Error> publishBodyFatal) {
var scopes = new ArrayDeque<AutoCloseable>();
Error bodyFatal = null;
try {
for (var plugin : plugins) {
try {
var scope = openHandlerScope(plugin);
if (scope != null) {
scopes.push(scope);
onScopeOpened.run();
}
} catch (Throwable e) {
reportHandlerScopeFailure("Plugin handler scope threw exception", e, onScopeFatal);
}
}
if (scopes.isEmpty() || publishBodyFatal == null) return handler.get();
try {
return handler.get();
} catch (Throwable failure) {
// Match the existing invocation body classifier, not the broader plugin/MDC wrapper policy.
var classified = ExceptionHelper.unwrapInvocationFailure(failure);
if (classified instanceof VirtualMachineError || classified instanceof ThreadDeath) {
bodyFatal = publishBodyFatal.apply((Error) classified);
}
ExceptionHelper.sneakyThrow(failure);
return null;
}
} finally {
closeHandlerScopes(scopes, onScopeFatal, bodyFatal);
}
}
@SuppressWarnings("unchecked")
private static AutoCloseable openHandlerScope(DurableExecutionPlugin plugin) throws ReflectiveOperationException {
var metadata = plugin.getClass().getAnnotation(HandlerScoped.class);
if (metadata == null) return null;
var constructor = metadata.value().getConstructor();
if (!constructor.canAccess(null) && !constructor.trySetAccessible()) {
throw new IllegalAccessException(
"Cannot access @HandlerScoped opener " + metadata.value().getName());
}
try {
var opener = (Function<Object, AutoCloseable>) constructor.newInstance();
return opener.apply(plugin);
} catch (InvocationTargetException failure) {
ExceptionHelper.sneakyThrow(failure.getCause());
return null;
}
}
@SuppressWarnings("removal")
private static void closeHandlerScopes(
ArrayDeque<AutoCloseable> scopes, Consumer<Error> onScopeFatal, Error bodyFatal) {
Error firstFatal = bodyFatal;
while (!scopes.isEmpty()) {
try {
scopes.pop().close();
} catch (Throwable e) {
try {
reportHandlerScopeFailure("Plugin handler scope cleanup threw exception", e, onScopeFatal);
} catch (VirtualMachineError | ThreadDeath fatal) {
if (firstFatal == null) firstFatal = fatal;
else if (firstFatal != fatal) firstFatal.addSuppressed(fatal);
}
}
}
if (firstFatal != null) throw firstFatal;
}
@SuppressWarnings("removal")
private static void reportHandlerScopeFailure(String message, Throwable failure, Consumer<Error> onScopeFatal) {
try {
contain(failure, message);
} catch (VirtualMachineError | ThreadDeath fatal) {
onScopeFatal.accept(fatal);
throw fatal;
}
}
public void onInvocationStart(InvocationInfo info) {
createPlugins(info);
}
/**
* Called at the end of each invocation. Awaited — the SDK blocks until all plugins return, allowing plugins to
* flush spans/metrics before Lambda freezes. The first fatal immediately stops outstanding operation work; an
* earlier invocation fatal retains precedence. Remaining plugins still receive their one finalization opportunity
* with the shared snapshot before the first end-hook fatal is rethrown.
*/
@SuppressWarnings("removal")
public void onInvocationEnd(InvocationEndInfo info) {
Error firstFatal = null;
for (int index = plugins.size() - 1; index >= 0; index--) {
var plugin = plugins.get(index);
try {
runPlugin(plugin, p -> p.onInvocationEnd(info));
} catch (VirtualMachineError | ThreadDeath fatal) {
if (firstFatal == null) {
firstFatal = fatal;
// Stop queued work before a later exporter can block, but still finalize every plugin below.
var primary = ExceptionHelper.unwrapAsyncFailure(info.executionError());
operationFatalObserver.accept(
primary instanceof VirtualMachineError || primary instanceof ThreadDeath
? (Error) primary
: firstFatal);
}
}
}
if (firstFatal != null) throw firstFatal;
}
@SuppressWarnings("removal")
private void runOperationHook(Consumer<DurableExecutionPlugin> hook) {
try {
run(hook);
} catch (VirtualMachineError | ThreadDeath fatal) {
operationFatalObserver.accept(fatal);
throw fatal;
}
}
public void onOperationStart(OperationInfo info) {
runOperationHook(p -> p.onOperationStart(info));
}
public void onOperationEnd(OperationEndInfo info) {
runOperationHook(p -> p.onOperationEnd(info));
}
public void onOperationChange(OperationChangeInfo info) {
runOperationHook(p -> p.onOperationChange(info));
}
public void onUserFunctionStart(UserFunctionStartInfo info) {
startUserFunctions(plugins, info, operationFatalObserver);
}
@SuppressWarnings("removal")
private static void startUserFunctions(
List<DurableExecutionPlugin> plugins, UserFunctionStartInfo info, Consumer<Error> operationFatalObserver) {
var started = new ArrayDeque<DurableExecutionPlugin>();
try {
for (var plugin : plugins) {
runPlugin(plugin, current -> {
current.onUserFunctionStart(info);
started.push(current);
});
}
} catch (VirtualMachineError | ThreadDeath fatal) {
// Publish the fatal before earlier cleanup can block, so cooperative peers can stop. The root handler
// still drains this actual owner before End; earlier starts unwind in LIFO order here.
operationFatalObserver.accept(fatal);
closeStartedUserFunctions(started, info, fatal);
throw fatal;
}
}
@SuppressWarnings("removal")
private static void closeStartedUserFunctions(
ArrayDeque<DurableExecutionPlugin> started, UserFunctionStartInfo info, Error fatal) {
var endInfo = PluginInfoConverter.toUserFunctionEndInfo(info, UserFunctionOutcome.FAILED, fatal);
while (!started.isEmpty()) {
try {
runPlugin(started.pop(), plugin -> plugin.onUserFunctionEnd(endInfo));
} catch (VirtualMachineError | ThreadDeath cleanupFailure) {
// Each earlier start gets its cleanup opportunity; preserve the original start-hook failure.
if (cleanupFailure != fatal) fatal.addSuppressed(cleanupFailure);
}
}
}
public void onUserFunctionEnd(UserFunctionEndInfo info) {
endUserFunctions(plugins, info, operationFatalObserver);
}
private static void endUserFunctions(
List<DurableExecutionPlugin> plugins, UserFunctionEndInfo info, Consumer<Error> operationFatalObserver) {
var fatal = closeUserFunctions(plugins, info, null, operationFatalObserver);
if (fatal != null) {
throw fatal;
}
}
/** Completes same-owner attempt cleanup after a peer fatal while retaining the invocation's original failure. */
public void onUserFunctionEndAfterFatal(UserFunctionEndInfo info, Error original) {
closeUserFunctions(plugins, info, original, operationFatalObserver);
}
private static Error closeUserFunctions(
List<DurableExecutionPlugin> plugins,
UserFunctionEndInfo info,
Error original,
Consumer<Error> operationFatalObserver) {
var first = original;
for (var plugin : plugins) {
try {
runPlugin(plugin, p -> p.onUserFunctionEnd(info));
} catch (Error cleanupFailure) {
if (first == null) {
first = cleanupFailure;
operationFatalObserver.accept(first);
} else if (cleanupFailure != first) first.addSuppressed(cleanupFailure);
}
}
return first;
}
/** Captures this invocation's attempt hook recipients without invoking factories or sharing plugin instances. */
public UserFunctionHooks captureUserFunctionHooks() {
var snapshot = plugins;
return snapshot.isEmpty() ? EMPTY_USER_FUNCTION_HOOKS : new UserFunctionHooks(snapshot, operationFatalObserver);
}
/**
* An operation owner retains these recipients through its matching end, until the invocation has drained its actual
* task.
*/
public static final class UserFunctionHooks {
private final List<DurableExecutionPlugin> plugins;
private final Consumer<Error> operationFatalObserver;
private UserFunctionHooks(List<DurableExecutionPlugin> plugins, Consumer<Error> operationFatalObserver) {
this.plugins = plugins;
this.operationFatalObserver = operationFatalObserver;
}
public void onUserFunctionStart(UserFunctionStartInfo info) {
startUserFunctions(plugins, info, operationFatalObserver);
}
public void onUserFunctionEnd(UserFunctionEndInfo info) {
endUserFunctions(plugins, info, operationFatalObserver);
}
public void onUserFunctionEndAfterFatal(UserFunctionEndInfo info, Error original) {
closeUserFunctions(plugins, info, original, operationFatalObserver);
}
}
}