On Friday, July 19, 2013 4:46:55 PM UTC+2, Flying-w wrote:
>
> I'm looking for some general guidance on implementing asynchronous calls 
> to a third party on the GWT Server side.  The scenario is the GWT client 
> side sends an RPC request to the server side, the server side does some 
> processing then needs to invoke a service in a remote third party.  The 
> call to the third party is asynchronous, the call is made and control is 
> return immediately.  Sometime later a callback is received with the actual 
> result from the service.  The challenge I have is what to do when i've made 
> the asynchronous call on the server side.  I don't want to "return" a 
> response back to the client side, as I really can't until the 3rd party has 
> called back.  How do I put myself into a "suspend" state until the callback 
> comes without unnecessarily tying up threads on the server?


Use "locks" to suspect the thread until the response comes back.

With Guava for instance, you can create a SettableFuture whose value will 
be set by the callback, and you then just "return future.get()" (or "return 
Futures.getUnchecked(future)"). The get() call is blocking until the 
SettableFuture's state is set (etiher to a value or an exception).
Without Guava, you could use a CountDownLatch of 1 for example.
FYI, Java 8 will have an equivalent of Guava's SettableFuture in the form 
of the CompletableFuture.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to