GWT and async requests (startAsync)

82 views
Skip to first unread message

rjcarr

unread,
Dec 22, 2016, 5:26:58 PM12/22/16
to GWT Users
I've had a long-poll implementation using gwt for a long time now. It defers the response until either an update or a timeout occurs. It works well, but it uses both a socket (inexpensive) and a thread (expensive), so I'd like this to use the async requests introduced in servlets 3.0. I've used async requests in non-gwt servlets and it's worked well.

In GWT however, once I've deferred the response, I can't figure out how to serialize the the response object once it's ready. For example, say I have this gwt-rpc method:

    public String longpoll()

Once inside I can defer the response with:

    getThreadLocalRequest().startAsync();


But once I'm ready to complete the response how is that String response serialized and returned (since I am no longer in the scope of the longpoll method)? (Note that the String response is just an example, in my case it's actually a custom object.)

Looking at the API for RemoteServiceServlet I don't see anything useful, except the onAfterResponseSerialized(String) which I can probably figure out how it works to come up with my own serialization, but this seems dangerous.

I think more generally my question is: is there any way to manually serialize an object and send it out with the response object?  I think if I knew that then it would solve all my problems.  

Thanks!

Thomas Broyer

unread,
Dec 23, 2016, 6:01:21 AM12/23/16
to GWT Users
GWT RPC has been thought of as blocking on the server side. Making it async would require changes to the RemoteServiceServlet: most likely the method would be async just like on the client side with the implementation calling the callbacks onSuccess or onFailure.

Your best bet here would be to write a RemoteServiceAsyncServlet by copying from RemoteServiceServlet, hoping for all underlying APIs to be public.
Either that or move off of RPC for that call (future proof)

Robert J. Carr

unread,
Dec 23, 2016, 12:41:25 PM12/23/16
to google-we...@googlegroups.com
Thanks Thomas. I was hoping it'd be easier and I was just missing something. Moving this call out of rpc is probably the best solution. Thanks again for the guidance!

Since servlets 3 had been out for a long time now it'd be a great idea to have the developers write this feature into RemoteServiceServlet. 
--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/-eITQalAc9k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages