Interface SourceCompletionCallback

All Superinterfaces:
org.mule.sdk.api.runtime.source.SourceCompletionCallback

@MinMuleVersion("4.1") @NoImplement public interface SourceCompletionCallback extends org.mule.sdk.api.runtime.source.SourceCompletionCallback
Callback used by 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 OnSuccess orOnError
  • 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 SourceCompletionCallback.success() or SourceCompletionCallback.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

    Methods inherited from interface org.mule.sdk.api.runtime.source.SourceCompletionCallback

    error, success