Interface SourceResultHandler<T,A>

Type Parameters:
T - the generic type of the result output value
A - the generic type of the result attributes value

@Experimental @MinMuleVersion("4.5.0") public interface SourceResultHandler<T,A>
Callback used by ExtensionsClient to notify of new results produced by a source created through the ExtensionsClient.createSource(String, String, Consumer, Consumer) method.

Clients will obtain the produced value by calling the getResult() method.

After processing the result, clients MUST invoke either completeWithSuccess(Consumer) or completeWithError(Throwable, Consumer), so that the source can finish the processing of each individual result. Refer to those method's javadocs for further details on their semantics.

NOTE: Experimental feature. Backwards compatibility not guaranteed.

Since:
1.5.0
  • Method Details

    • getResult

      Result<T,A> getResult()
      Returns:
      a Result produced by the message source
    • completeWithSuccess

      CompletableFuture<Void> completeWithSuccess(Consumer<SourceCallbackParameterizer> successCallbackParameters)
      Executes the source's completion callback. This method MUST be invoked when the client has successfully processed the getResult(), even if the SourceModel doesn't explicitly define a success SourceCallbackModel.

      The actual effect of calling this method will depend on the source (some will emit a response back to the client, some will update internal state, etc.). The action is however asynchronous, for which the method returns a CompletableFuture, which will either complete with a void value or an Exception.

      Unlike what happens with a source created inside a Mule app, should this method fail (either synchronously upon invocation or asynchronously with an exceptional completion of the return future), the completeWithError(Throwable, Consumer) method will not be called automatically.

      Finally, this method should only be called at most once per instance and should be mutually exclusive with completeWithError(Throwable, Consumer), which means that if one is called, the other one shouldn't.

      Parameters:
      successCallbackParameters - parameterizes the source's success callback.
      Returns:
      a CompletableFuture
    • completeWithError

      CompletableFuture<Void> completeWithError(Throwable exception, Consumer<SourceCallbackParameterizer> errorCallbackParameters)
      Executes the source's error callback. This method MUST be invoked when the client has encountered an Exception while processing the getResult() which should be notified back to the source so that it considers the Result as a failed event. This must be done even if the SourceModel doesn't explicitly define an error SourceCallbackModel.

      The actual effect of calling this method will depend on the source (some will emit a response back to the client, some will update internal state, etc.). The action is however asynchronous, for which the method returns a CompletableFuture, which will either complete with a void value or an Exception.

      Finally, this method should only be called at most once per instance and should be mutually exclusive with completeWithSuccess(Consumer), which means that if one is called, the other one shouldn't.

      Parameters:
      exception - The exception found
      errorCallbackParameters - parameterizes the source's error callback.
      Returns:
      a CompletableFuture