Package io.karatelabs.core
Class ScenarioLockManager
java.lang.Object
io.karatelabs.core.ScenarioLockManager
Manages locks for parallel scenario execution.
Supports two types of locks via the @lock tag:
@lock=<name>- Named lock for mutual exclusion. Scenarios with the same lock name will run sequentially, but scenarios with different lock names can run concurrently.@lock=*- Exclusive lock. The scenario runs exclusively - no other scenarios can run concurrently, even those with different lock names.
Implementation uses a read-write lock pattern:
- Named locks acquire the global read lock (allows concurrent execution with other named locks)
- Exclusive locks acquire the global write lock (blocks all other scenarios)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHandle for releasing acquired locks. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe special lock name that indicates exclusive execution. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAcquire locks for a scenario based on its @lock tags.voidRelease locks previously acquired for a scenario.
-
Field Details
-
EXCLUSIVE_LOCK
The special lock name that indicates exclusive execution.- See Also:
-
-
Constructor Details
-
ScenarioLockManager
public ScenarioLockManager()
-
-
Method Details
-
acquire
Acquire locks for a scenario based on its @lock tags. Returns a handle that must be used to release the locks.All scenarios acquire at least the global read lock to ensure @lock=* scenarios can truly run exclusively. The overhead is minimal (~100ns) for uncontended read locks.
- Parameters:
scenario- the scenario to acquire locks for- Returns:
- a LockHandle to release the locks (never null)
-
release
Release locks previously acquired for a scenario.- Parameters:
handle- the lock handle returned by acquire()
-