Hi Tal,

The call to stop() is not necessary and was left from a previous version based 
on the Client class. I've just fixed it. Regarding exhaust() behavior, a 
significant change was made in version 2.0.0 based on David Fogel's feedback. 
This method now systematically closes the underlying stream after eating all 
the content. 

Note that calling Response#release() currently only releases the entity if 
available:

    public void release() {
        if (getEntity() != null) {
            getEntity().release();
        }
    }

Regarding the proper way to close the underlying connection, it is in fact the 
ClientResource#abort() or Request#abort() method that should be called. I've 
clarified this in the wiki page:
http://wiki.restlet.org/docs_2.1/13-restlet/27-restlet/328-restlet/285-restlet.html

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg
Noelios Technologies ~ http://www.noelios.com



-----Message d'origine-----
De : Tal Liron [mailto:[email protected]] 
Envoyé : vendredi 31 décembre 2010 17:11
À : [email protected]
Objet : Re: response.release() versus response.exhaust() in 2.0

I am a still unclear as to the best practice.


In the example you give on the wiki, you call stop() on the resource, and there 
is no try/catch, but you do not mention whether using stop() is a good idea.


In relation to the last paragraph -- my experience has shown that
exhaust() is not good enough (Restlet 2.0.x, Apache HTTP Client), and still 
leads to hanging threads. Even calling release() on the representation is not 
good enough. I found that the only way to avoid hangs is a complete release() 
of the *response*, and I found this out only through  searching in the mailing 
list. While this does avoid hanging my application, it seems like this is not 
recommended. Can you clarify?


-Tal


On 12/31/2010 03:39 AM, Jerome Louvel wrote:

> Hi all,
>
> I've updated the wiki to clarify this best practice, see the last section:
> http://wiki.restlet.org/docs_2.0/285-restlet.html
>
> The Javadocs have also been previously clarified before, saying that 
> release() should rarely be called:
> http://www.restlet.org/documentation/2.0/jee/api/org/restlet/represent
> ation/Representation.html#release%28%29
>
> I've clarified this even further in SVN (2.0 and trunk) by adding this 
> paragraph:
>       * Note that calling this method will likely prevent the reuse of the
>       * underlying persistent connection and therefore should only be called 
> when
>       * exhausting the content with {...@link #exhaust()} is too costly or 
> when
>       * further calls from the client are not welcome.
>
> Hope this clarifies. We can update the wiki/javadocs further based on your 
> experienced. If one connector such as Apache HTTP Client 4 doesn't work 
> consistently with this description, we can try to fix it.
>
> Best regards,
> Jerome
> --
> Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg Noelios 
> Technologies ~ http://www.noelios.com
>
>
>
>
>
> -----Message d'origine-----
> De : Rickard Öberg [mailto:[email protected]] Envoyé : vendredi 
> 31 décembre 2010 03:18 À : [email protected] Objet : Re: 
> response.release() versus response.exhaust() in 2.0
>
> On 2010-12-31 05.55, Tal Liron wrote:
>> pool.) It's probably best to employ a try-finally paradigm, where the 
>> try clause contains as little code as possible, and the finally 
>> clause releases the response. See the example below.
>>
>> var fixture
>> var resource =
>> document.external('file:///myfiles/fixture.json','application/json')
>> try {
>>      fixture = resource.get().text
>>
>> }
>> finally {
>>      resource.response.release()
>> }
> So this, combined with Jerome's reply:
>>       >>  1) release() has the effect of closing the underlying TCP
>>      socket, preventing persistent connection reuse. So it can't be
>>      recommended to systematically call it.
> basically means that we can't have persistent connection reuse on the client. 
> Correct or not?
>
> /Rickard
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId
> =2695100
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId
> =2695151

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695206

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695509

Reply via email to