Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] Connection Management Issue ,Please help


I am doing POC on jetty http2 client,i am using jetty version 9.3.7.v20160115. Below is my code snippet.

I am facing one problem ,i.e. in below code snippet ,i have for loop where i am making 3000 requests and i have set Max Requests Queued Per Destination as 2000.after sending 2000 requests,jetty API is aborting requests by throwing "RequestRejectedException",but this exception is not propagated to caller. at this point of time i want to close the connection and i want to open the new connection for handling the remaining 1000 requests.can you please suggest me How do i close connection now? on what basis i should close connection? until I receive the responses of 2000 Requests i can not close connection since i am handling responses asynchronously.


 public class Test{

             public static void main(String args[]){

                ALPN.debug = true;
       HTTP2Client http2Client = new HTTP2Client();
       http2Client.start();             
       
       SslContextFactory ssl = new SslContextFactory(true);
       ssl.setKeyStore(getKeyStore());
       ssl.setKeyStorePassword("");
       
       HttpClient client = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), ssl);

   System.out.println("-----Max request per destination"
+ client.getMaxRequestsQueuedPerDestination());
       client.setMaxRequestsQueuedPerDestination(2000);
       
System.out.println("client.getMaxRequestsQueuedPerDestination()"
+ client.getMaxRequestsQueuedPerDestination());
       
       client.start();
       
       
       long start =System.currentTimeMillis();    

       for (int i=0;i<3000;i++){
       
       
       System.out.println("Sending" + i);

       
       Request req = client.POST("https://www.google.com");

       req.send(new ResponseListener(i,"")); 
      }
        
}
}


Handling Response Asynchronously

public class ResponseListener extends BufferingResponseListener{
    
    int id = 0;
    int j = 0;

    private String threadName;

    public ResponseListener(int i, String threadName) {
        super();
        id = i;
        this.threadName = threadName;
    }

 

    @Override
    public void onComplete(Result result) {
        try {
       
            System.out.println("Current thread name in ResponseListener -"
                    + Thread.currentThread().getName());

            Response response = result.getResponse();
            //System.out.println("Response .." + response);
            int status = response.getStatus();
            if (status == 200) {
                System.out.println("ID-" + id + ",Success");
            }
            else {
                System.out.println("ID-" + id + ",Failure. status code " + status + ", response"
                        + getContentAsString());
            }
        }
        catch (Throwable t) {
            t.printStackTrace();
        }
    }

}

Back to the top