Class RateLimitExecutor
java.lang.Object
ai.nervemind.app.executor.RateLimitExecutor
- All Implemented Interfaces:
NodeExecutor
Executor for the "rate_limit" node type - throttles operations using rate
limiting algorithms.
Prevents overwhelming external services by limiting the rate of operations. Supports two rate limiting strategies: Token Bucket (smooth rate limiting) and Sliding Window (strict per-window limits). Rate limit buckets are shared globally across workflow executions.
Node Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| operations | List | [] | Operations to execute with rate limiting |
| bucketId | String | "default" | Rate limit bucket identifier |
| strategy | String | "token_bucket" | "token_bucket" or "sliding_window" |
| waitForTokens | Boolean | true | Wait for tokens if unavailable |
| maxWaitMs | Long | 60000 | Max wait time for tokens |
Token Bucket Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| tokensPerSecond | Double | 10.0 | Rate of token refill |
| maxTokens | Integer | 100 | Maximum bucket capacity |
| tokensPerRequest | Integer | 1 | Tokens consumed per request |
Sliding Window Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| windowSizeMs | Long | 1000 | Window duration in milliseconds |
| maxRequestsPerWindow | Integer | 10 | Max requests per window |
Output Data
| Key | Type | Description |
|---|---|---|
| success | Boolean | True if rate limit acquired and operation succeeded |
| throttled | Boolean | True if request was rejected due to rate limit |
| waitedMs | Long | Time spent waiting for rate limit |
| tokensRemaining | Double | Tokens left (token bucket only) |
| requestsInWindow | Integer | Requests in window (sliding window only) |
Shared Buckets
Buckets are stored in static ConcurrentHashMaps and shared across
all workflow executions. Use unique bucketIds to isolate rate limits.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRateLimitExecutor(NodeExecutorRegistry nodeExecutorRegistry) Creates a new RateLimitExecutor with the given node executor registry. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClear all rate limit buckets.static voidclearBucket(String bucketId) Clear a specific bucket.execute(ai.nervemind.common.domain.Node node, Map<String, Object> input, ExecutionService.ExecutionContext context) Executes the business logic for this node type.Unique identifier for the node type this executor handles.
-
Constructor Details
-
RateLimitExecutor
Creates a new RateLimitExecutor with the given node executor registry.- Parameters:
nodeExecutorRegistry- the registry for accessing other node executors
-
-
Method Details
-
getNodeType
Description copied from interface:NodeExecutorUnique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.- Specified by:
getNodeTypein interfaceNodeExecutor- Returns:
- The unique type string (e.g., "httpRequest", "llmChat").
-
execute
public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String, Object> input, ExecutionService.ExecutionContext context) Description copied from interface:NodeExecutorExecutes the business logic for this node type.- Specified by:
executein interfaceNodeExecutor- Parameters:
node- The node definition containing parameters and configuration. UseNode.parameters()to access user settings.input- Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.context- Verification context providing access to workflow-scoped services, logger, and execution metadata.- Returns:
- A Map containing the results of this node's execution.
Keys in this map become available variables for downstream nodes.
Note: Returningnullis treated as an empty map.
-
clearAllBuckets
public static void clearAllBuckets()Clear all rate limit buckets. Useful for testing. -
clearBucket
Clear a specific bucket.- Parameters:
bucketId- the ID of the bucket to clear
-