|
75 | 75 | * // @link substring="newInstance" target="#newInstance" :
|
76 | 76 | * private static final ScopedValue<String> NAME = ScopedValue.newInstance();
|
77 | 77 | *
|
78 |
| - * // @link substring="runWhere" target="#runWhere(ScopedValue, Object, Runnable)" : |
79 |
| - * ScopedValue.runWhere(NAME, "duke", () -> doSomething()); |
| 78 | + * // @link substring="run" target="Carrier#run(Runnable)" : |
| 79 | + * ScopedValue.where(NAME, "duke").run(() -> doSomething()); |
80 | 80 | * }
|
81 | 81 | * Code executed directly or indirectly by {@code doSomething}, with access to the field
|
82 | 82 | * {@code NAME}, can invoke {@code NAME.get()} to read the value "{@code duke}". {@code
|
83 | 83 | * NAME} is bound while executing the {@code run} method. It reverts to being unbound when
|
84 | 84 | * the {@code run} method completes.
|
85 | 85 | *
|
86 |
| - * <p> The example using {@code runWhere} invokes a method that does not return a result. |
87 |
| - * The {@link #callWhere(ScopedValue, Object, CallableOp) callWhere} method can be used |
| 86 | + * <p> The example using {@code run} invokes a method that does not return a result. |
| 87 | + * The {@link Carrier#call(CallableOp) call} method can be used |
88 | 88 | * to invoke a method that returns a result.
|
89 |
| - * In addition, {@code ScopedValue} defines the {@link #where(ScopedValue, Object)} method |
| 89 | + * {@code ScopedValue} defines the {@link #where(ScopedValue, Object)} method |
90 | 90 | * for cases where multiple mappings (of {@code ScopedValue} to value) are accumulated
|
91 | 91 | * in advance of calling a method with all {@code ScopedValue}s bound to their value.
|
92 | 92 | *
|
93 | 93 | * <h2>Bindings are per-thread</h2>
|
94 | 94 | *
|
95 |
| - * A {@code ScopedValue} binding to a value is per-thread. Invoking {@code xxxWhere} |
| 95 | + * A {@code ScopedValue} binding to a value is per-thread. Invoking {@code run} |
96 | 96 | * executes a method with a {@code ScopedValue} bound to a value for the current thread.
|
97 | 97 | * The {@link #get() get} method returns the value bound for the current thread.
|
98 | 98 | *
|
99 | 99 | * <p> In the example, if code executed by one thread invokes this:
|
100 | 100 | * {@snippet lang=java :
|
101 |
| - * ScopedValue.runWhere(NAME, "duke1", () -> doSomething()); |
| 101 | + * ScopedValue.where(NAME, "duke1").run(() -> doSomething()); |
102 | 102 | * }
|
103 | 103 | * and code executed by another thread invokes:
|
104 | 104 | * {@snippet lang=java :
|
105 |
| - * ScopedValue.runWhere(NAME, "duke2", () -> doSomething()); |
| 105 | + * ScopedValue.where(NAME, "duke2").run(() -> doSomething()); |
106 | 106 | * }
|
107 | 107 | * then code in {@code doSomething} (or any method that it calls) invoking {@code NAME.get()}
|
108 | 108 | * will read the value "{@code duke1}" or "{@code duke2}", depending on which thread is
|
|
129 | 129 | * <p> In the above example, suppose that code executed by {@code doSomething} binds
|
130 | 130 | * {@code NAME} to a new value with:
|
131 | 131 | * {@snippet lang=java :
|
132 |
| - * ScopedValue.runWhere(NAME, "duchess", () -> doMore()); |
| 132 | + * ScopedValue.where(NAME, "duchess").run(() -> doMore()); |
133 | 133 | * }
|
134 | 134 | * Code executed directly or indirectly by {@code doMore()} that invokes {@code
|
135 | 135 | * NAME.get()} will read the value "{@code duchess}". When {@code doMore()} completes
|
|
157 | 157 | * {@snippet lang=java :
|
158 | 158 | * private static final ScopedValue<String> NAME = ScopedValue.newInstance();
|
159 | 159 |
|
160 |
| - * ScopedValue.runWhere(NAME, "duke", () -> { |
| 160 | + * ScopedValue.where(NAME, "duke").run(() -> { |
161 | 161 | * // @link substring="open" target="StructuredTaskScope#open(Policy)" :
|
162 | 162 | * try (var scope = StructuredTaskScope.open(policy)) {
|
163 | 163 | *
|
@@ -414,7 +414,6 @@ public <T> T get(ScopedValue<T> key) {
|
414 | 414 | * @return the result
|
415 | 415 | * @throws StructureViolationException if a structure violation is detected
|
416 | 416 | * @throws X if {@code op} completes with an exception
|
417 |
| - * @see ScopedValue#callWhere(ScopedValue, Object, CallableOp) |
418 | 417 | * @since 23
|
419 | 418 | */
|
420 | 419 | public <R, X extends Throwable> R call(CallableOp<? extends R, X> op) throws X {
|
@@ -463,7 +462,6 @@ private <R, X extends Throwable> R runWith(Snapshot newSnapshot, CallableOp<R, X
|
463 | 462 | *
|
464 | 463 | * @param op the operation to run
|
465 | 464 | * @throws StructureViolationException if a structure violation is detected
|
466 |
| - * @see ScopedValue#runWhere(ScopedValue, Object, Runnable) |
467 | 465 | */
|
468 | 466 | public void run(Runnable op) {
|
469 | 467 | Objects.requireNonNull(op);
|
@@ -533,77 +531,6 @@ public static <T> Carrier where(ScopedValue<T> key, T value) {
|
533 | 531 | return Carrier.of(key, value);
|
534 | 532 | }
|
535 | 533 |
|
536 |
| - /** |
537 |
| - * Calls a value-returning operation with a {@code ScopedValue} bound to a value |
538 |
| - * in the current thread. When the operation completes (normally or with an |
539 |
| - * exception), the {@code ScopedValue} will revert to being unbound, or revert to |
540 |
| - * its previous value when previously bound, in the current thread. If {@code op} |
541 |
| - * completes with an exception then it propagated by this method. |
542 |
| - * |
543 |
| - * <p> Scoped values are intended to be used in a <em>structured manner</em>. If code |
544 |
| - * invoked directly or indirectly by the operation creates a {@link StructuredTaskScope} |
545 |
| - * but does not {@linkplain StructuredTaskScope#close() close} it, then it is detected |
546 |
| - * as a <em>structure violation</em> when the operation completes (normally or with an |
547 |
| - * exception). In that case, the underlying construct of the {@code StructuredTaskScope} |
548 |
| - * is closed and {@link StructureViolationException} is thrown. |
549 |
| - * |
550 |
| - * @implNote |
551 |
| - * This method is implemented to be equivalent to: |
552 |
| - * {@snippet lang=java : |
553 |
| - * // @link substring="call" target="Carrier#call(CallableOp)" : |
554 |
| - * ScopedValue.where(key, value).call(op); |
555 |
| - * } |
556 |
| - * |
557 |
| - * |
558 |
| - * |
559 |
| - * @param key the {@code ScopedValue} key |
560 |
| - * @param value the value, can be {@code null} |
561 |
| - * @param <T> the type of the value |
562 |
| - * @param <R> the result type |
563 |
| - * @param <X> type of the exception thrown by the operation |
564 |
| - * @param op the operation to call |
565 |
| - * @return the result |
566 |
| - * @throws StructureViolationException if a structure violation is detected |
567 |
| - * @throws X if the operation completes with an exception |
568 |
| - * @since 23 |
569 |
| - */ |
570 |
| - public static <T, R, X extends Throwable> R callWhere(ScopedValue<T> key, |
571 |
| - T value, |
572 |
| - CallableOp<? extends R, X> op) throws X { |
573 |
| - return where(key, value).call(op); |
574 |
| - } |
575 |
| - |
576 |
| - /** |
577 |
| - * Run an operation with a {@code ScopedValue} bound to a value in the current |
578 |
| - * thread. When the operation completes (normally or with an exception), the |
579 |
| - * {@code ScopedValue} will revert to being unbound, or revert to its previous value |
580 |
| - * when previously bound, in the current thread. If {@code op} completes with an |
581 |
| - * exception then it propagated by this method. |
582 |
| - * |
583 |
| - * <p> Scoped values are intended to be used in a <em>structured manner</em>. If code |
584 |
| - * invoked directly or indirectly by the operation creates a {@link StructuredTaskScope} |
585 |
| - * but does not {@linkplain StructuredTaskScope#close() close} it, then it is detected |
586 |
| - * as a <em>structure violation</em> when the operation completes (normally or with an |
587 |
| - * exception). In that case, the underlying construct of the {@code StructuredTaskScope} |
588 |
| - * is closed and {@link StructureViolationException} is thrown. |
589 |
| - * |
590 |
| - * @implNote |
591 |
| - * This method is implemented to be equivalent to: |
592 |
| - * {@snippet lang=java : |
593 |
| - * // @link substring="run" target="Carrier#run(Runnable)" : |
594 |
| - * ScopedValue.where(key, value).run(op); |
595 |
| - * } |
596 |
| - * |
597 |
| - * @param key the {@code ScopedValue} key |
598 |
| - * @param value the value, can be {@code null} |
599 |
| - * @param <T> the type of the value |
600 |
| - * @param op the operation to call |
601 |
| - * @throws StructureViolationException if a structure violation is detected |
602 |
| - */ |
603 |
| - public static <T> void runWhere(ScopedValue<T> key, T value, Runnable op) { |
604 |
| - where(key, value).run(op); |
605 |
| - } |
606 |
| - |
607 | 534 | private ScopedValue() {
|
608 | 535 | this.hash = generateKey();
|
609 | 536 | }
|
|
0 commit comments