Tuesday 15 February 2011

java - How to notify "content consumed" for Jetty 9.02. ContentListener? -



java - How to notify "content consumed" for Jetty 9.02. ContentListener? -

i have jetty httpclient sending async requests using jetty v9.0.2. have response.contentlistener buffers-up response , response.compeletelistener called when phone call has completed.

jetty 9.2 javadocs has request.asynccontentlistener has parameter tell jetty content has been consumed: callback - callback phone call when content consumed.

this listener type not in jetty v9.0.2 response api:

import org.eclipse.jetty.client.api.result;

there 2 questions really:

does response.contentlistener need notify jetty client content consumed? if so: how managed jetty v9.0.2 what kind of clean-up required using async calls these 2 response.contentlistener , response.compeletelistener set-up? are there potential gottchas using async jetty v9.0.2?

it seems working fine; need ensure have no resource leaks or potential leaks, etc. , of course of study need programme nice , clean can run 24x7. thanks in advance welcome help.

note:

request.asynccontentlistener - stable jetty doc (jetty 9.2, believe)

the short reply question phone call httpclient.stop() after async phone call has completed processing. solution approach outlined in tutorial example:

jetty's http client

the main aspect stop() may not called until (all) listeners have finished-up , processing has completed. in illustration above, countdownlatch used synchronize stop() call. isn't explained in jetty examples, e.g.:

the new jetty 9 http client chapter 28. http client - asynchronous apis class httpclient

some async interfaces utilize calls "consume content", etc. jetty 9 stop() phone call clean-up.

our use-case straight forwards enough. in oncomplete() method in listener, phone call made setcompleted() method decrements count downwards latch httpclient.send(). next send() call, have synchronization method called, finished() wait on phone call setcompleted().

public boolean finish(){ boolean result = false; int retrycount = 0; seek { if( !this.latch.await( 5, timeunit.seconds ) ) { util.warn(log,"timed-out -- msg #", string.format("%0,4d", this.msgid) ); } this.httpclient.stop(); result = this.httpclient.isstopped(); } grab (interruptedexception ex ) { log.warn("interrupted -- msg #", string.format("%0,4d", this.msgid)" ); } grab (exception ex) { log.error(log,"stop-exception -- msg #", string.format("%0,4d", this.msgid) ); } if( !result ) { log.warn(" * httpclient not stopped -- msg #", string.format("%0,4d", this.msgid) ); } homecoming result; }

the stop phone call seems happy phone call long setcompleted() called @ end of our oncomplete() method. i'm not clear if can't sure of internal timing oncomplete. otherwise seems satisfactory. believe api documentation should include "clean-up code" opertations of kind - info comms, database, etc. posting save time others.

java asynchronous listener jetty-9 resource-cleanup

No comments:

Post a Comment