Class PersistBarrier
java.lang.Object
com.google.adk.flows.llmflows.PersistBarrier
Lets
BaseLlmFlow's multi-step loop wait until the Runner -- the sole event
persister -- has appended the current step's events, so the next step's request (built from
session.events() by Contents) is not assembled from a stale session. The
Runner calls markPersisted(InvocationContext, String) (or markFailed(InvocationContext, String, Throwable)) after each append; the flow calls
awaitPersisted(InvocationContext, List) between steps. State lives in the per-invocation InvocationContext.callbackContextData() map, shared across the agent tree.
Each event id maps to a CompletableSubject: pending until its append finishes, then
terminally completed or failed. The subject retains its terminal state, so
awaitPersisted/mark* may happen in any order and a late await -- e.g. at a higher flow
level across an agent transfer -- resolves immediately. If an append fails, the matching await
fails with that error rather than blocking forever.
Thread-safe and lock-free: markPersisted/markFailed may run off-thread (async
appendEvent) concurrently with awaitPersisted; ConcurrentHashMap.computeIfAbsent(K, Function) hands both sides the same subject, which
itself serializes its terminal signal against subscription.
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.reactivex.rxjava3.core.CompletableawaitPersisted(InvocationContext context, List<Event> events) Completes once every event ineventshas beenmarkPersisted(InvocationContext, String), or fails if any wasmarkFailed(InvocationContext, String, Throwable); completes immediately if the barrier was neverenable(InvocationContext)d.static voidenable(InvocationContext context) Marks that aRunneris driving this invocation and will resolve each appended event.static voidmarkFailed(InvocationContext context, String eventId, Throwable error) Signals that persisting the event with the given id failed, so an await on it fails witherrorinstead of blocking forever.static voidmarkPersisted(InvocationContext context, String eventId) Signals that theRunnerpersisted the event with the given id.
-
Method Details
-
enable
Marks that aRunneris driving this invocation and will resolve each appended event. Otherwise (flow run directly, e.g. unit tests)awaitPersisted(InvocationContext, List)is a no-op, avoiding a deadlock waiting for a signal that never comes. -
awaitPersisted
public static io.reactivex.rxjava3.core.Completable awaitPersisted(InvocationContext context, List<Event> events) Completes once every event ineventshas beenmarkPersisted(InvocationContext, String), or fails if any wasmarkFailed(InvocationContext, String, Throwable); completes immediately if the barrier was neverenable(InvocationContext)d. Already-resolved events resolve immediately, so the order ofawaitPersisted/mark*does not matter. -
markPersisted
Signals that theRunnerpersisted the event with the given id. -
markFailed
Signals that persisting the event with the given id failed, so an await on it fails witherrorinstead of blocking forever.
-