How to delay execution of onPostExecute() method till api calls are complete - android-asynctask

Am making an api call from asynctask's doInBackground() method. I want asynctask to execute onPostExecute() method only after receiving response of this api call. Is this possible?

The default functionality of AsyncTask is, onPostExecute() will be called only when doInBAckground() method is completed.
If this is not happening, please share the code.

Related

What is the right way to dubug context cancellation for a grpc call?

I am working on an go application, that uses gin to serve the rest APIs.
I 4 of my handler functions for the APIs call a goroutine which makes a gRPC call. A strange thing i see, all the grpc calls for one of the handler fails with context cancelled while the other 3 succeed.
Looking at the logs, i noticed that my API returns before the goroutine is executed. Could it be possible that gin cancels the context after the API returns?
The context is propagated from the handler function to the goroutine through a couple of intermediate calls.
The error that i see is rpc error: code = Canceled desc = context canceled
How can i debug this? Does gin cancel the context once it returns the response?
Does gin cancel the context once it returns the response?
The docs for Request.Context() (gin uses http.Request) say:
For incoming server requests, the context is canceled when the client's connection closes, the request is canceled (with HTTP/2), or when the ServeHTTP method returns.
So, yes, the context is closed when your handler (effectively the ServeHTTP method) returns (see here). The context would also be cancelled if the connection dropped for another reason (network issue, or even your server shutting down).
The right way to handle this really depends upon what you want to achieve:
In many cases the correct behaviour is to cancel the RPC calls when the context is cancelled. For example if you are retrieving info needed to fulfil the request then cancelling those requests may save resources.
If you are triggering calls that must complete then pass in a context.Background() (or another context not directly tied to the request).
How can i debug this?
Look at why your handler is returning before all RPC calls complete; if that is what you want then you will need to use a different context (but remember this probably means you are returning an OK response code when you don't actually know yet if the entire process will be successful).

How does Apache Camel AS2 handle async mdn

i have a very simple route as a as2 server:
from("as2://server/listen?serverPortNumber=7777&requestUriPattern=/").id("as2Listener").bean(AS2Controller.class);
when i receive an async mdn from my partner, I see in the log that the AS2 Server components receive an incoming as2 request and it process the request, but it doesn't get into the process method in my controller class (normal as2 messages from my partner gets process in the process method in the controller class no problem). Can anyone help with where the mdn message gets processed in the whole flow?
Thanks!
Edit:
Normal AS2 Request can get process fine, but when I receive a MDN message, it doesn't get passed into my controller, instead there is this error before and it quits before passing it over:
The Error Message I get when I receive a mdn message
If you are developing the code on Spring Boot, you can call bean method by "as2controller" (which you give the name) or you can autowire the class and call it directly.
#Autowired
AS2Controller as2controller ;
//.bean(as2controller);
More info, https://camel.apache.org/components/latest/bean-component.html

Phonegap sends notifications inside ajax request

I am trying to get notification on android/ios. I have an ajax request inside a setinterval function, and I want it to notify me, when the ajax request turns true.
Can anyone ever try to do this or did this before?
I already try to use plugin push, but actually I don't know, how it works.

Why not spring amqp provider a sendAndAsyncReceive method signature?

Sometime we need send a message asynchronous and provide a callback when message result asynchronous returned.
Now,there is only blocking method sendAndReceive;why not provider a sendAndAsyncReceive method by pass a callback arg or return a listentablefuture?
Because nobody has asked for it.
You can use send() and configure an async consumer (SimpleMessageListenerContainer) to receive the replies.
Feel free to open a new feature JIRA issue or, even better, consider contributing.
EDIT:
Here's a gist with sample code.

How to test that async controller is really running async

I have created simple async controllers that call into async methods that then call PostAsync on the HttpClient to retrieve various REST service endpoints. All works well, but how can I test to insure that the controller is really calling a background thread and releasing the primary thread back to the pool? I want to insure that I do have all the async sweetness working correctly and that I am not inadvertently running synchronous methods despite all my work to make everything async.
I found that System.Threading.Thread.CurrentThread.IsThreadPoolThread will provide whether the current thread is still a threadpool thread or not.

Resources