Class ResourceLimits.Builder
- Enclosing class:
ResourceLimits
- Since:
- 19.3
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the limit configuration object.onLimit
(Consumer<ResourceLimitEvent> onLimit) Notified when a resource limit is reached.statementLimit
(long limit, Predicate<Source> sourceFilter) Specifies the maximum number of statements a context may execute until the onLimit event is notified and the context will beclosed
.
-
Method Details
-
statementLimit
Specifies the maximum number of statements a context may execute until the onLimit event is notified and the context will beclosed
. After the statement limit was triggered for a context, it is no longer usable and every use of the context will throw aPolyglotException
that returnstrue
forPolyglotException.isCancelled()
. The statement limit is independent of the number of threads executing and is applied per context. Invoking this method multiple times overwrites previous statement limit configurations. If the statement limit is exceeded then theonLimit
listener is notified.By default there is no statement limit applied. The limit may be set to 0 to disable it. In addition to the limit a source filter may be set to indicate for which sources the limit should be applied. If the source filter is
null
then it will be applied to allinternal
and public sources. The provided limit must not be negative otherwise anIllegalArgumentException
is thrown. If ashared engine
is used then the same source filter instance must be used for all contexts of an engine. Otherwise anIllegalArgumentException
is thrown when the context isbuilt
. The limit itself may vary between contexts.The statement limit is applied to the context and all inner contexts it spawns. Therefore, new inner contexts cannot be used to exceed the statement limit.
Note that attaching a statement limit to a context reduces the throughput of all guest applications with the same engine. The statement counter needs to be updated with every statement that is executed. It is recommended to benchmark the use of the statement limit before it is used in production.
Note that the complexity of a single statement may not be constant time depending on the guest language. For example, statements that execute JavaScript builtins, like
Array.sort
, may account for a single statement, but its execution time is dependent on the size of the array. The statement count limit is therefore not suitable to perform time boxing and must be combined with other more reliable measures.- Since:
- 19.3
- See Also:
-
onLimit
Notified when a resource limit is reached. Default isnull
. May be set tonull
to disable events.- Since:
- 19.3
-
build
Builds the limit configuration object.- Since:
- 19.3
- See Also:
-