Package com.facilita.fc.web
Class ConcurrentRequestSender
- java.lang.Object
-
- com.facilita.fc.web.ConcurrentRequestSender
-
public class ConcurrentRequestSender extends java.lang.Object
Provides methods for sending multipleRequest
objects 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 void
addRequest(Request request)
Add aRequest
to the list of requests that will be sent to the web server by a call tosendRequests()
.void
delete()
static long
getCPtr(ConcurrentRequestSender obj)
For internal use only.java.util.List<Response>
getResponses()
void
sendRequests()
Sends a list ofRequest
objects 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
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 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 aRequest
to the list of requests that will be sent to the web server by a call tosendRequests()
.- Parameters:
request
- theRequest
to add.- See Also:
sendRequests()
-
sendRequests
public void sendRequests() throws BadValueException
Sends a list ofRequest
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 ofResponse
objects, where each response corresponds to aRequest
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 aRequest
that was sent - Throws:
com.facilita.exception.InternalError
- An error occurred- See Also:
sendRequests()
,addRequest(Request)
-
-