sources in order tell the runtime that they will process the flow's response in an asynchronous
manner (from now on, async sources).
Main uses cases for async sources are (but not limited to):
- Response operation is non-blocking way
- Response operation is blocking, but it's asynchronously executed in a thread other than the one which initiates it (most
typically, the thread executing a method annotated with
OnSuccessorOnError - The source wants to perform asynchronous auditing for which it needs to consume a response stream in a separate thread
In those use cases, the runtime needs to know that the response will be asynchronous because otherwise it will generate a race condition between the thread emitting the response and the runtime itself which is trying to free up resources associated with the message being responded to.
In those use cases, the methods annotated with OnSuccess or OnError can have an argument of this type. That's
enough to signal the runtime that the source is an async one. The runtime will not finish the associated event until either
success() or error(Throwable) methods are invoked. Notice this is a very strong piece of the contract. A
source which requests a SourceCompletionCallback but then doesn't properly notifies it is one likely to eventually
freeze the entire runtime!.
Let's see a quick example:
@OnSuccess
public void onSuccess(@Content String response, SourceCompletionCallback callback) {
asyncResponder.sendResponse(response, new ResponderCallback() {
void onSuccess() {
callback.success();
}
void onFailure(Throwable t) {
callback.error(t);
}
}
}
- Since:
- 1.0
-
Method Summary
-
Method Details
-
success
void success()Signals the runtime that it has successfully processed the response -
error
Signals the runtime that the response was processed, but with an error- Parameters:
t- the catched error
-