Interface RunContextPropagator
- All Known Implementing Classes:
MicrometerRunContextPropagator,OpenTelemetryRunContextPropagator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Restate.run(java.lang.String, java.lang.Class<T>, dev.restate.common.function.ThrowingSupplier<T>) closure.
Restate.run(java.lang.String, java.lang.Class<T>, dev.restate.common.function.ThrowingSupplier<T>) closures are scheduled on the Executor provided in HandlerRunner.Options.setExecutor(Executor). Thread-local state installed on the handler thread
(e.g. by a HandlerInterceptor opening a tracing span / observation scope, MDC values,
security context, …) is not visible there by default. Implementations of this interface capture
that state at submission time and restore it around the closure execution.
capture() is invoked on the handler thread (or whatever thread calls Restate.run(java.lang.String, java.lang.Class<T>, dev.restate.common.function.ThrowingSupplier<T>)) at submission time; RunContextPropagator.CapturedContext.wrap(java.lang.Runnable) is invoked later, and the
resulting Runnable executes on the worker thread. The classic shape is:
() -> {
var captured = captureCurrentThreadState();
return runnable -> () -> {
try (var scope = captured.install()) {
runnable.run();
}
};
}
Propagators are discovered via ServiceLoader (global defaults) or registered
explicitly via HandlerRunner.Options.addRunContextPropagator(RunContextPropagator). They apply
to every Restate.run(java.lang.String, java.lang.Class<T>, dev.restate.common.function.ThrowingSupplier<T>) execution, including retries.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptioncapture()Capture a thread-local state from the calling thread.static RunContextPropagatorcombine(Collection<? extends RunContextPropagator> propagators) static RunContextPropagatorcombine(Stream<? extends RunContextPropagator> propagators) Combine multiple propagators into a singleRunContextPropagator.
-
Method Details
-
capture
RunContextPropagator.CapturedContext capture()Capture a thread-local state from the calling thread. -
combine
Combine multiple propagators into a singleRunContextPropagator.capture()captures with all propagators in registration order; at wrap time the first propagator restores outermost. -
combine
-