Class DeferredResponse<T>
java.lang.Object
dev.langchain4j.agentic.internal.DeferredResponse<T>
- Type Parameters:
T- the type of the response value
- All Implemented Interfaces:
DelayedResponse<T>
- Direct Known Subclasses:
PendingResponse, SuspendedResponse
Abstract base for responses that are deferred to an external actor (e.g., a human,
a REST endpoint, a message queue) and must be explicitly completed via
complete(Object).
After serialization/deserialization, a new incomplete CompletableFuture is created,
allowing an external system to reconnect and complete the response.
Concrete subclasses determine the runtime behavior when the response is not yet available:
PendingResponse— blocks the calling thread until completed (future semantic)SuspendedResponse— suspends the agentic system by throwingAgenticSystemSuspendedException(exception semantic)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionblockingGet(long timeout, TimeUnit unit) Waits for the response with a timeout.booleanCompletes this deferred response with the given value.booleancompleteExceptionally(Throwable exception) Completes this deferred response exceptionally.booleanisDone()Returns the unique identifier for this deferred response.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface DelayedResponse
result
-
Constructor Details
-
DeferredResponse
-
-
Method Details
-
responseId
Returns the unique identifier for this deferred response.- Returns:
- the response identifier
-
isDone
public boolean isDone()- Specified by:
isDonein interfaceDelayedResponse<T>
-
blockingGet
- Specified by:
blockingGetin interfaceDelayedResponse<T>
-
blockingGet
Waits for the response with a timeout.- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the response value
- Throws:
TimeoutException- if the wait timed out
-
complete
Completes this deferred response with the given value. Any threads blocked onblockingGet()will be released.- Parameters:
value- the response value- Returns:
trueif this invocation caused the response to transition to a completed state,falseif it was already completed
-
completeExceptionally
Completes this deferred response exceptionally.- Parameters:
exception- the exception- Returns:
trueif this invocation caused the response to transition to a completed state
-
toString
-