Class ConcurrentRequestSender


  • public class ConcurrentRequestSender
    extends java.lang.Object
    Provides methods for sending multiple Request objects to the web server concurrently.
    • Constructor Detail

      • ConcurrentRequestSender

        public ConcurrentRequestSender​(long cPtr,
                                       boolean cMemoryOwn)
        For internal use only. Of no interest to the user.
        Parameters:
        cPtr - pointer to the CPP wrapped object
        cMemoryOwn - indicates if this object is responsible for memory management of the CPP object
      • ConcurrentRequestSender

        public ConcurrentRequestSender​(int maxConcurrency)
        Creates a new ConcurrentRequestSender, specifying the maximum number of concurrent requests to send to the web server.

        If maxConcurrency is less than or equal to zero, then all the requests will be sent concurrently.

        Parameters:
        maxConcurrency - the maximum concurrency to allow.
      • ConcurrentRequestSender

        public ConcurrentRequestSender()
        Creates a new ConcurrentRequestSender.

        All the requests will be sent concurrently (equivalent to ConcurrentRequestSender(0)).

    • Method Detail

      • getCPtr

        public static long getCPtr​(ConcurrentRequestSender obj)
        For internal use only. Of no interest to the user.
        Parameters:
        obj - a reference to an object of this class
        Returns:
        a long containing the address of the CPP wrapped object
      • delete

        public void delete()
      • sendRequests

        public void sendRequests()
                          throws BadValueException
        Sends a list of Request objects to the web server in parallel.

        e.g.

        
         // Send 4 requests in a parallel
         try (ConcurrentRequestSender requestSender = new ConcurrentRequestSender()) {
             requestSender.addRequest(getWebBrowser().createRequest(HttpMethod.GET, new Url("http://localhost:32144/Themes/TestPlant/Content/images/orange_button_bg.gif")));
             requestSender.addRequest(getWebBrowser().createRequest(HttpMethod.GET, new Url("http://localhost:32144/Themes/TestPlant/Content/images/bg_maincolumn_3.gif")));
             requestSender.addRequest(getWebBrowser().createRequest(HttpMethod.GET, new Url("http://localhost:32144/Themes/TestPlant/Content/images/logo-reflection.gif")));
             requestSender.addRequest(getWebBrowser().createRequest(HttpMethod.GET, new Url("http://localhost:32144/Themes/TestPlant/Content/images/ico-register.gif")));
             requestSender.sendRequests();
             List<Response> responses = requestSender.getResponses();
         } 
         
        Throws:
        BadValueException - An internal error occurred.
        See Also:
        getResponses(), addRequest(Request)
      • getResponses

        public java.util.List<Response> getResponses()
                                              throws com.facilita.exception.InternalError
        Get a list of Response objects, where each response corresponds to a Request that was sent. The list is in the order in which the responses were received.
        Returns:
        a list of Response objects, where each response corresponds to a Request that was sent
        Throws:
        com.facilita.exception.InternalError - An error occurred
        See Also:
        sendRequests(), addRequest(Request)