Interface CompletionCallback<T,A>

Type Parameters:
T - The generic type of the operation's output value
A - The generic type of the operation's output attributes
All Known Subinterfaces:
RouterCompletionCallback

@MinMuleVersion("4.1") @NoImplement public interface CompletionCallback<T,A>
This callback is how non blocking operations notify their outcome.

In order to implement a non blocking operation, the method needs to:

  • Have a void return type
  • Have an argument of this type, with its generics correctly provided

The operation's output will be derived from the generics, so even though the method is void, the runtime will consider the operation to return values of the generic types.

When the non blocking operation has finished, it has to notify the result either by invoking the success(Result) or error(Throwable) methods. Only then will the operation be considered as completed and the next processor in the pipeline will be executed.

For example, let's see a very simple non blocking http request


  public void request(String path, @Content Object content, CompletionCallback<InputStream, HttpAttributes> callback) {
    httpClient.requestNonBlocking(path, content, new HttpClientCallback() {
      void onSuccess(HttpResponse response) {
        callback.onSuccess(Result.<InputStream, HttpAttributes>.builder()
          .output(response.getBody())
          .attributes(toAttributes(response))
          .build());
      }

      void onFailure(Exception e) {
        callback.onException(e);
       }
    }
  }
 

If the operation is void, the Void type can be used in the generics.

Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method is not be invoked when the operation failed to execute.
    void
    success(Result<T,A> result)
    This method is to be invoked with the operation's result.
  • Method Details

    • success

      void success(Result<T,A> result)
      This method is to be invoked with the operation's result. The value itself has to be provided with a Result instance.
      Parameters:
      result - the operation's result
    • error

      void error(Throwable e)
      This method is not be invoked when the operation failed to execute.
      Parameters:
      e - the exception found