users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: some more on AsyncResponse

From: Bill Burke <bburke_at_redhat.com>
Date: Thu, 16 Aug 2012 15:41:49 -0400

On 8/16/2012 2:35 PM, Marek Potociar wrote:
>
> On Aug 16, 2012, at 5:39 PM, Bill Burke <bburke_at_redhat.com> wrote:
>
>> * Why have a separate setTimeoutHandler() method? Why not just create and register a TimeoutCallback?
>
> because you may want to change the timeout values (e.g. from within the TimeoutHandler)
>

Why can't this be implemented as a callback?

TimeoutCallback.timeout(AsyncResponse res) {

    res.resume(Response.status(500).build());

}

>>
>> * register() returns a boolean in some instances and AsyncResponse in others and the javadoc is off. IMO, you don't need a boolean return value , instead throw an UnsupportedOperationException or something.
>
> Fixed, nice catch. The decision to return boolean rather than failing is to provide optional (impl. specific) callback support. IOW, users may register even callbacks that are not understood and implementation should work normally, just without calling those callbacks. (See also the definition of OPTIONAL.)
>
>>
>> * If anything, ResumeCallback happens before response is sent, isn't this what a ContainerResponseFilter already does? Also, how could ResumeCallback modify the response?
>
> It doesn't. It's a listener.
>

I don't get it then. Why invoke it before the actual response is sent
back if you can't modify the response?

>> Call AsyncResponse.resume()?
>
> Should not, but implementations should prevent this.
>
>> If so, how can you avoid an infinite loop?
>
> Up to implementation to prevent this.
>
>> I question all this behavior.
>>
>> * I don't like the current behavior of ResumeCallback and think it should be removed.
>>
>> * I think we should have similar Servlet 3.0 callbacks.
>>
>> CompletionCallback
>> OnErrorCallback
>
> Please define the API for those 2.

Same as ResumeCallback except it gets called after a response is sent
back to the client instead of before.

interface CompletionCallback {

    void completed(AsyncResponse res, Response res) {
    }
}


Called when there was an error sending the response back to the client.

interface ErrorCallback {

    void error(AsyncResponse res, Response res) {
    }
}


>
>> TimeoutCallback
>
> We have a TimeoutHandler. Since this is the special type of callback that may modify the execution state, I prefer we keep it separate from other callbacks that are intended to be used as pure listeners.

If you look at the Servlet AsyncListener, onComplete() and onError() are
basically pure listeners, while onTimeout() allows you to modify
execution state.


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com