Class RequestBundler
java.lang.Object
co.ecg.alpaca.toolkit.messaging.request.RequestBundler
- All Implemented Interfaces:
AutoCloseable
The RequestBundler is created via the BroadWorksServer and serves as a
queueing mechanism for sending Requests by packaging them in bundles of 15
before sending them via OCI.
- Author:
- Matthew Keathley on 11/19/2015
-
Constructor Summary
ConstructorsConstructorDescriptionRequestBundler
(LibraryProperties libraryProperties, org.springframework.context.ApplicationContext applicationContext) Creates a new RequestBundler -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
fire()
Fires the RequestBundler.getLock()
org.apache.commons.lang3.mutable.MutableInt
int
<R extends Response>
voidpostResponse
(Request<R> request, ResponseBundle responseBundle) Posts the response from the response bundle to the mapped request.<R extends Response>
CompletableFutureAdds a Request to the RequestBundler to be completed in the next outgoing bundle.<R extends Response>
CompletableFutureAdds a Request to the RequestBundler to be completed in the next outgoing bundle.resendAlone
(Request<? extends Response> request) Resends a Request that already has a response handler in the RequestMap.void
start
(BroadWorksServer broadWorksServer) Starts the requestbundler for the given BroadWorksServervoid
waitForCondition
(BooleanSupplier condition) This sleeps the thread until the provided condition is met or the async load timeout occurs as specified in the configuration file.
-
Constructor Details
-
RequestBundler
@Autowired public RequestBundler(LibraryProperties libraryProperties, org.springframework.context.ApplicationContext applicationContext) Creates a new RequestBundler
-
-
Method Details
-
start
Starts the requestbundler for the given BroadWorksServer- Parameters:
broadWorksServer
- The BroadWorksServer for this Bundler
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getResponseService
-
getOutstandingBundleCount
public org.apache.commons.lang3.mutable.MutableInt getOutstandingBundleCount() -
getQueueSize
public int getQueueSize() -
fire
Fires the RequestBundler. This can occur manually, due to reaching 15 requests in the bundle, or due to the BundlerTimer reaching the timeout.- Returns:
- A Future with the ResponseBundle for this set of requests or NULL if the request queue is empty
-
postResponse
Posts the response from the response bundle to the mapped request.If the ResponseBundle is null -- due to a socket timeout for exampe - the request is removed from the map but the consumer is not fired.
- Type Parameters:
R
- The response type.- Parameters:
request
- The request to retrieve a response from the bundle.responseBundle
- The response bundle for the request bundle.
-
resendAlone
Resends a Request that already has a response handler in the RequestMap. This request is fired using alone to prevent contamination.- Parameters:
request
- The request to send- Returns:
- A Future with the ResponseBundle for this resent request
-
put
public <R extends Response> CompletableFuture put(Request<R> request, Consumer<R> consumer, boolean forceFire) Adds a Request to the RequestBundler to be completed in the next outgoing bundle. The request is potentially immediately sent.If the request is null or invalid it will not be added to the backing bundle. A null consumer is allowed but the response will be ignored.
- Type Parameters:
R
- The Response type- Parameters:
request
- The request to sendconsumer
- The consumer of the responseforceFire
- Force the firing of the request bundle.
-
put
Adds a Request to the RequestBundler to be completed in the next outgoing bundle. This does not force firing. The Future will return null if there are less than 15 requests currently in the queue.If the request is null or invalid it will not be added to the backing bundle. A null consumer is allowed but the response will be ignored.
- Type Parameters:
R
- The Response type- Parameters:
request
- The request to sendconsumer
- The consumer of the response
-
waitForCondition
This sleeps the thread until the provided condition is met or the async load timeout occurs as specified in the configuration file. The timeout resets as long as requests continue to be completed.- Parameters:
condition
- The condition that must be true before continuing.
-
getLock
-