Package com.facilita.fc.web
Class ConcurrentRequestSender
- java.lang.Object
-
- com.facilita.fc.web.ConcurrentRequestSender
-
public class ConcurrentRequestSender extends java.lang.ObjectProvides methods for sending multipleRequestobjects to the web server concurrently.
-
-
Constructor Summary
Constructors Constructor Description ConcurrentRequestSender()Creates a newConcurrentRequestSender.ConcurrentRequestSender(int maxConcurrency)Creates a newConcurrentRequestSender, specifying the maximum number of concurrent requests to send to the web server.ConcurrentRequestSender(long cPtr, boolean cMemoryOwn)For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRequest(Request request)Add aRequestto the list of requests that will be sent to the web server by a call tosendRequests().voiddelete()static longgetCPtr(ConcurrentRequestSender obj)For internal use only.java.util.List<Response>getResponses()voidsendRequests()Sends a list ofRequestobjects to the web server in parallel.
-
-
-
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 objectcMemoryOwn- indicates if this object is responsible for memory management of the CPP object
-
ConcurrentRequestSender
public ConcurrentRequestSender(int maxConcurrency)
Creates a newConcurrentRequestSender, specifying the maximum number of concurrent requests to send to the web server.If
maxConcurrencyis 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 newConcurrentRequestSender.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()
-
addRequest
public void addRequest(Request request)
Add aRequestto the list of requests that will be sent to the web server by a call tosendRequests().- Parameters:
request- theRequestto add.- See Also:
sendRequests()
-
sendRequests
public void sendRequests() throws BadValueExceptionSends a list ofRequestobjects 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 ofResponseobjects, where each response corresponds to aRequestthat was sent. The list is in the order in which the responses were received.- Returns:
- a list of
Responseobjects, where each response corresponds to aRequestthat was sent - Throws:
com.facilita.exception.InternalError- An error occurred- See Also:
sendRequests(),addRequest(Request)
-
-