java.lang.Object
jdk.incubator.concurrent.ExtentLocal.Carrier
- Enclosing class:
ExtentLocal<T>
An immutable map of extent-local variables to values.
It define the
run and call methods
to invoke an operation with the extent-local variable mappings bound to the thread
that invokes run or call.- Since:
- 19
-
Method Summary
Modifier and TypeMethodDescription<R> RRuns a value-returning operation with this map of extent-local variables bound to values.<T> Tget(ExtentLocal<T> key) Returns the value of a variable in this map of extent-local variables.voidRuns an operation with this map of ExtentLocals bound to values.where(ExtentLocal<T> key, T value) Returns a newCarrier, which consists of the contents of this carrier plus a new mapping fromkeytovalue.
-
Method Details
-
where
Returns a newCarrier, which consists of the contents of this carrier plus a new mapping fromkeytovalue. If this carrier already has a mapping for the extent-local variablekeythen the new value added by this method overrides the previous mapping. That is to say, if there is a list ofwhere(...)clauses, the rightmost clause wins.- Type Parameters:
T- the type of the ExtentLocal- Parameters:
key- the ExtentLocal to bind a value tovalue- the new value, can benull- Returns:
- a new carrier, consisting of
thisplus a new binding (thisis unchanged)
-
get
Returns the value of a variable in this map of extent-local variables.- Type Parameters:
T- the type of the ExtentLocal- Parameters:
key- the ExtentLocal variable- Returns:
- the value
- Throws:
NoSuchElementException- if key is not bound to any value
-
call
Runs a value-returning operation with this map of extent-local variables bound to values. Code invoked byopcan use thegetmethod to get the value of the extent local. The extent-local variables revert to their previous values or become unbound when the operation completes.Extent-local variables are intended to be used in a structured manner. If
opcreates anyStructuredTaskScopes but does not close them, then exitingopcauses the underlying construct of eachStructuredTaskScopeto be closed (in the reverse order that they were created in), andStructureViolationExceptionto be thrown.- Type Parameters:
R- the type of the result of the function- Parameters:
op- the operation to run- Returns:
- the result
- Throws:
Exception- ifopcompletes with an exception
-
run
Runs an operation with this map of ExtentLocals bound to values. Code executed by the operation can use theget()method to get the value of the extent local. The extent-local variables revert to their previous values or becomes unbound when the operation completes.Extent-local variables are intended to be used in a structured manner. If
opcreates anyStructuredTaskScopes but does not close them, then exitingopcauses the underlying construct of eachStructuredTaskScopeto be closed (in the reverse order that they were created in), andStructureViolationExceptionto be thrown.- Parameters:
op- the operation to run
-