| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | ////This file is included by every high level rest client API documentation pageso we don't have to copy and paste the same asciidoc over and over again. We*do* have to copy and paste the same Java tests over and over again. For nowthis is intentional because it forces us to *write* and execute the testswhich, while a bit ceremonial, does force us to cover these calls in *some*test.////[id="{upid}-{api}-sync"]==== Synchronous ExecutionWhen executing a +{request}+ in the following manner, the client waitsfor the +{response}+ to be returned before continuing with code execution:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-execute]--------------------------------------------------[id="{upid}-{api}-async"]==== Asynchronous ExecutionExecuting a +{request}+ can also be done in an asynchronous fashion so thatthe client can return directly. Users need to specify how the response orpotential failures will be handled by passing the request and a listener to theasynchronous {api} method:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-execute-async]--------------------------------------------------<1> The +{request}+ to execute and the `ActionListener` to use whenthe execution completesThe asynchronous method does not block and returns immediately. Once it iscompleted the `ActionListener` is called back using the `onResponse` methodif the execution successfully completed or using the `onFailure` method ifit failed.A typical listener for +{response}+ looks like:["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{doc-tests-file}[{api}-execute-listener]--------------------------------------------------<1> Called when the execution is successfully completed.<2> Called when the whole +{request}+ fails.
 |