Hi Rob,
> Google Web Toolkit compiles Java to Javascript and runs it in the context
of a
> Web browser. In this context, only one type of Client is of critical
import,
> the XmlHttpRequest facility provided by the browser. This is typically an
> asynchronous mechanism. While it is possible (in most browsers) to use
the
> XmlHttpRequest in a blocking way, it's neither idiomatic nor desirable in
most
> cases. The mechanisms built into GWT are all very callback-driven, and
> GWT-REST echoes this design.
I fully share your analysis.
[...]
> do we want to try to ensure that this works in "GWT-Restlet" by blocking
at
> client.handle(request),
For having used GWT daily over the past 8 months, trying to reproduce the
blocking mode in GWT seems unnatural to me. Are you aware of safe and
efficient mechanisms to "block" in GWT while waiting for a given "event" to
occur?
I found this post:
"http request synchronous"
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/8473f
c342dfa3fe8
and this blog post:
"No, we don't do synchronous"
http://web.kellegous.com/ecrits/001096
The conclusion seems to be: no synchronous calls in Restlet-GWT :-)
> or do we want to provide something in the callback
> style, like
>
> Client client = new Client(Protocol.HTTP);
> Response response = client.handleCallback(request, response, new
> UniformCallback(){
> void handle(Request request,Response response){
> if (response.getStatus().isSuccess()) {
> System.out.println("Hurray");
> }
> }
> });
>
> Or yet another approach, which I have no notion of as yet ...
I agree with the UniformCallback approach. Let's just try to step back from
the pure client call use case to embrace more complex client-side use cases.
For example, we should be able to use Filters or client-side Resources in
the future, in an asynchronous way.
It seems that we could first try to convert the Uniform base class to
something like this:
Uniform
-------
void delete(Reference resourceRef, UniformCallback callback)
void delete(String resourceUri, UniformCallback callback)
void get(Reference resourceRef, UniformCallback callback)
void get(String resourceUri, UniformCallback callback)
void handle(Request request, UniformCallback callback)
void head(Reference resourceRef, UniformCallback callback)
void head(String resourceUri, UniformCallback callback)
void options(Reference resourceRef, UniformCallback callback)
void options(String resourceUri, UniformCallback callback)
void post(Reference resourceRef, Representation entity, UniformCallback
callback)
void post(String resourceUri, Representation entity, UniformCallback
callback)
void put(Reference resourceRef, Representation entity, UniformCallback
callback)
void put(String resourceUri, Representation entity, UniformCallback
callback)
Note that the handle(Request,Response) method could be removed, as it is of
little usage for an asynchronous client-side API.
UniformCallback
---------------
void onCompletion(Request request, Response response);
BTW, this could give us some good hints for our asynchronous RFE:
http://restlet.tigris.org/issues/show_bug.cgi?id=143
Best regards,
Jerome