Class RequestBundler

java.lang.Object
co.ecg.alpaca.toolkit.messaging.request.RequestBundler
All Implemented Interfaces:
AutoCloseable

@Component @Scope("prototype") public class RequestBundler extends Object implements 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 Details

    • RequestBundler

      @Autowired public RequestBundler(LibraryProperties libraryProperties, org.springframework.context.ApplicationContext applicationContext)
      Creates a new RequestBundler
  • Method Details

    • start

      public void start(BroadWorksServer broadWorksServer)
      Starts the requestbundler for the given BroadWorksServer
      Parameters:
      broadWorksServer - The BroadWorksServer for this Bundler
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getResponseService

      public ExecutorService 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

      public <R extends Response> void postResponse(Request<R> request, ResponseBundle responseBundle)
      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

      public CompletableFuture<ResponseBundle> resendAlone(Request<? extends Response> request)
      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 send
      consumer - The consumer of the response
      forceFire - Force the firing of the request bundle.
    • put

      public <R extends Response> CompletableFuture put(Request<R> request, Consumer<R> consumer)
      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 send
      consumer - The consumer of the response
    • waitForCondition

      public void 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. The timeout resets as long as requests continue to be completed.
      Parameters:
      condition - The condition that must be true before continuing.
    • getLock

      public Lock getLock()