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

I have a Jetty HttpClient sending Async requests using Jetty v9.0.2. I have a Response.ContentListener that successfully buffers and a Response.CompeleteListener that is called when the call is completed.

This type of listener is NOT in Jetty v9.0.2 Response api:

  • import org.eclipse.jetty.client.api. Result ;

There are actually two questions:

  • Does Response.ContentListener need to tell the Jetty client that the content is being consumed?
    • If yes: how did it succeed with Jetty v9.0.2
  • What kind of cleanup will I need with Async calls with these two settings, Response.ContentListener and Response.CompeleteListener?
    • Are there any potential gottchas using async with Jetty v9.0.2?

It seems to be working fine; I need to make sure that we have no resource leaks or potential leaks, etc. And, of course, we need a program to be beautiful and clean so that it can work 24x7. Thank you in advance for your welcome help.

Note:

0
source share
1 answer

The short answer to this question is to call HttpClient.stop () after the asynchronous call completes. This case study describes a solution approach:

The main aspect is that Stop () cannot be called until (all) listeners have finished and completed processing. The above example uses a CountdownLatch to synchronize the stop () call. This is not explained in Jetty examples, for example:

Some asynchronous interfaces use calls, such as consume content, etc. However, with Jetty 9, the stop () call does the cleanup.

Our precedent was fairly straightforward. In the onComplete () method, a call to the setCompleted () method is performed in the listener, which reduces the count delay for Httpclient.send (). After calling send (), we have a synchronization method called completed () that waits for setCompleted () to be called.

public boolean finish(){ boolean result = false; int retryCount = 0; try { 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(); } catch (InterruptedException ex ) { log.warn("Interrupted -- msg #", String.format("%0,4d", this.msgId)" ); } catch (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) ); } return result; } 

The stop call seems to be pleased with the call while setCompleted () is called at the end of our onComplete () method. I donโ€™t understand if you can be sure of the internal time for onComplete. Otherwise, all this seems satisfactory. I really believe that API documentation should include a โ€œcleanup codeโ€ for such operations - data, data, etc. Hope this post saves others time.

0
source

Source: https://habr.com/ru/post/1487800/


All Articles