Class DefaultConcurrentRequestsHandler

java.lang.Object
com.seeq.link.sdk.utilities.DefaultConcurrentRequestsHandler
All Implemented Interfaces:
ConcurrentRequestsHandler

public class DefaultConcurrentRequestsHandler extends Object implements ConcurrentRequestsHandler
There are two main use-cases for concurrent requests 1. Limit the number of concurrent requests per connection In this case each connection will have its own instance of this class. 2. Limit the number of concurrent requests per connector In this case the connector will create an instance of this class and share it between its connections. This is useful for connectors like Python ExtCalc where each script corresponds to a connection, and therefore, for optimal CPU usage we should have the possibility to set maxConcurrentRequests per connector. Basically in this case we limit the number of parallel Python processes.
  • Constructor Details

    • DefaultConcurrentRequestsHandler

      public DefaultConcurrentRequestsHandler(int maxConcurrentRequests)
  • Method Details

    • runWhenPermitted

      public Thread runWhenPermitted(Runnable request, ThreadCollection threadCollection, long timeoutMillis, long requestId, com.seeq.utilities.ManualResetEvent requestThreadStartedEvent)
      Description copied from interface: ConcurrentRequestsHandler
      Ensures that only a specific number of requests will be executed in parallel.
      Specified by:
      runWhenPermitted in interface ConcurrentRequestsHandler
      Parameters:
      request - Concurrent task to be executed
      threadCollection - Thread collection used to spawn a new thread for the request
      timeoutMillis - Amount of time to wait for request completion
      requestId - Request identifier
      requestThreadStartedEvent - Manual reset event which will be set after the thread of the request is started. The thread may be waiting for permission to run its job, but we are sure the thread is started when the event is set.
      Returns:
      the thread of the executed request
    • getMaxConcurrentRequests

      public int getMaxConcurrentRequests()
      Specified by:
      getMaxConcurrentRequests in interface ConcurrentRequestsHandler
      Returns:
      the maximum number of concurrent requests. When this limit is exceeded, any call of runWhenPermitted will block the execution of the request until an execution slot is available.
    • getRegisteredRequestsCount

      public int getRegisteredRequestsCount()
      Specified by:
      getRegisteredRequestsCount in interface ConcurrentRequestsHandler
      Returns:
      the number of registered requests. May be different than the number of requests currently executed.