Package com.seeq.link.sdk.utilities
Class DefaultConcurrentRequestsHandler
java.lang.Object
com.seeq.link.sdk.utilities.DefaultConcurrentRequestsHandler
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
int
runWhenPermitted
(Runnable request, ThreadCollection threadCollection, long timeoutMillis, long requestId, com.seeq.utilities.ManualResetEvent requestThreadStartedEvent) Ensures that only a specific number of requests will be executed in parallel.
-
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 interfaceConcurrentRequestsHandler
- Parameters:
request
- Concurrent task to be executedthreadCollection
- Thread collection used to spawn a new thread for the requesttimeoutMillis
- Amount of time to wait for request completionrequestId
- Request identifierrequestThreadStartedEvent
- 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 interfaceConcurrentRequestsHandler
- 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 interfaceConcurrentRequestsHandler
- Returns:
- the number of registered requests. May be different than the number of requests currently executed.
-