execution.asciidoc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ////
  2. This file is included by every high level rest client API documentation page
  3. so we don't have to copy and paste the same asciidoc over and over again. We
  4. *do* have to copy and paste the same Java tests over and over again. For now
  5. this is intentional because it forces us to *write* and execute the tests
  6. which, while a bit ceremonial, does force us to cover these calls in *some*
  7. test.
  8. ////
  9. [id="{upid}-{api}-sync"]
  10. ==== Synchronous Execution
  11. When executing a +{request}+ in the following manner, the client waits
  12. for the +{response}+ to be returned before continuing with code execution:
  13. ["source","java",subs="attributes,callouts,macros"]
  14. --------------------------------------------------
  15. include-tagged::{doc-tests-file}[{api}-execute]
  16. --------------------------------------------------
  17. [id="{upid}-{api}-async"]
  18. ==== Asynchronous Execution
  19. Executing a +{request}+ can also be done in an asynchronous fashion so that
  20. the client can return directly. Users need to specify how the response or
  21. potential failures will be handled by passing the request and a listener to the
  22. asynchronous {api} method:
  23. ["source","java",subs="attributes,callouts,macros"]
  24. --------------------------------------------------
  25. include-tagged::{doc-tests-file}[{api}-execute-async]
  26. --------------------------------------------------
  27. <1> The +{request}+ to execute and the `ActionListener` to use when
  28. the execution completes
  29. The asynchronous method does not block and returns immediately. Once it is
  30. completed the `ActionListener` is called back using the `onResponse` method
  31. if the execution successfully completed or using the `onFailure` method if
  32. it failed.
  33. A typical listener for +{response}+ looks like:
  34. ["source","java",subs="attributes,callouts,macros"]
  35. --------------------------------------------------
  36. include-tagged::{doc-tests-file}[{api}-execute-listener]
  37. --------------------------------------------------
  38. <1> Called when the execution is successfully completed.
  39. <2> Called when the whole +{request}+ fails.