Skip to content

Commit 2b46ffd

Browse files
committed
Add package javadoc for API module.
This fixes #591 Signed-off-by: Sjoerd Talsma <sjoerdtalsma@users.noreply.github.com>
1 parent ddd2c5d commit 2b46ffd

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

context-propagation-api/src/main/java/nl/talsmasoftware/context/api/Context.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public interface Context extends Closeable {
4545
* <p>
4646
* It is the responsibility of the one activating a new context to also close it <em>from the same thread</em>.
4747
*
48-
* @implSpec It <strong>must</strong> be possible to call the {@linkplain #close()} method multiple times. Later calls must have no effect and should not throw exceptions.
48+
* @implSpec It <strong>must</strong> be possible to call the {@linkplain #close()} method multiple times.
49+
* Later calls must have no effect and should not throw exceptions.
4950
* @implNote Implementors are advised to <em>restore</em> the previous thread-local value upon close, but are not obliged to do so.
5051
*/
5152
void close();

context-propagation-api/src/main/java/nl/talsmasoftware/context/api/ContextManager.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,34 @@
1919
* Manages a {@linkplain Context} by providing a standard way of interacting with {@linkplain ThreadLocal} values.
2020
*
2121
* <p>
22+
* Thread-local values can be accessed via a ContextManager by:
23+
*
24+
* <p>
2225
* {@linkplain ThreadLocal} values can be accessed via a ContextManager by:
2326
* <ul>
27+
* <li>Calling {@linkplain #getActiveContextValue()} which <em>gets</em> the current thread-local value.
2428
* <li>Calling {@linkplain #activate(Object)} which <em>sets</em> the given value until {@linkplain Context#close()}
25-
* is called on the resulting {@linkplain Context}.
26-
* <li>Calling {@linkplain #getActiveContextValue()} which <em>sets</em> the current thread-local value.
29+
* is called on the returned {@linkplain Context}.
2730
* <li>Calling {@linkplain #clear()} which <em>removes</em> the thread-local value.
2831
* </ul>
2932
*
30-
* <p>
31-
* Implementations must be made available through the {@linkplain java.util.ServiceLoader ServiceLoader}.<br>
32-
* For details how to make your implementation available, please see the documentation of {@link java.util.ServiceLoader}.
33-
*
3433
* @param <T> type of the context value
3534
* @author Sjoerd Talsma
35+
* @implSpec Implementations <strong>must</strong> be made available through Java's ServiceLoader.
36+
* For details how to make your implementation available, please see the documentation of {@link java.util.ServiceLoader}.
3637
* @since 2.0.0
3738
*/
3839
public interface ContextManager<T> {
39-
4040
/**
4141
* Activate a new context containing the specified <code>value</code>.
4242
*
4343
* <p>
4444
* Whether the value is allowed to be <code>null</code> is up to the implementation.
4545
*
46+
* <p>
47+
* The specified value is the <em>active</em> value for the current thread,
48+
* until the returned {@linkplain Context} is closed, or another value gets activated.
49+
*
4650
* @param value The value to activate a new context for.
4751
* @return The new <em>active</em> context containing the specified value
4852
* which should be closed by the caller at the end of its lifecycle from the same thread.
@@ -58,16 +62,15 @@ public interface ContextManager<T> {
5862
T getActiveContextValue();
5963

6064
/**
61-
* Clears the current context and any potential parent contexts that exist.
65+
* Clears the current context and any potential parent contexts that exist, for the current thread.
6266
*
6367
* <p>
6468
* This is an optional operation.<br>
6569
* When all active contexts are initialized in combination with try-with-resources blocks,
6670
* it is not necessary to call clear.
6771
*
6872
* <p>
69-
* The operation exists to allow thread pool management making sure
70-
* to clear all contexts before returning threads to the pool.
73+
* The operation exists to allow thread-pool management to clear all contexts before returning threads to the pool.
7174
*
7275
* <p>
7376
* This method normally should only get called by {@linkplain #clearAll()}.

context-propagation-api/src/main/java/nl/talsmasoftware/context/api/ContextSnapshot.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919
import java.util.concurrent.Callable;
2020

2121
/**
22-
* Snapshot capturing all active values from detected {@link ContextManager} implementations.
22+
* Captures active values from all detected {@linkplain ContextManager} implementations.
2323
*
2424
* <p>
25-
* Such a snapshot can be passed to another thread,
26-
* allowing all captured values to be reactivated in that other thread by a single method call.
27-
*
28-
* <p>
29-
* A context snapshot can be obtained from the {@linkplain #capture()} method.
25+
* A context snapshot can be obtained from the {@linkplain #capture()} method.<br>
26+
* The captured values in this snapshot can be reactivated in another thread.
3027
*
3128
* <p>
3229
* <strong>Important:</strong> Make sure to <strong>always</strong> call {@link Reactivation#close()}

context-propagation-api/src/main/java/nl/talsmasoftware/context/api/package-info.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,41 @@
1414
* limitations under the License.
1515
*/
1616
/**
17-
* API concepts used throughout the {@code context-propagation} library.
17+
* The API of the {@code context-propagation} library.
18+
*
19+
* <h2>{@linkplain nl.talsmasoftware.context.api.ContextSnapshot}</h2>
20+
* <p>
21+
* Captures active values from all detected {@linkplain nl.talsmasoftware.context.api.ContextManager} implementations.
22+
*
23+
* <p>
24+
* The captured values in a snapshot can be reactivated in another thread.<br>
25+
* Snapshot reactivations must be closed again to avoid leaking context.
1826
*
19-
* <h2>{@linkplain nl.talsmasoftware.context.api.Context}</h2>
2027
* <p>
21-
* A {@linkplain nl.talsmasoftware.context.api.Context context} contains a value.<br>
22-
* There can be one active context per thread. A context remains active until it is closed or another context
23-
* is activated in the same thread. Normally, a context is backed by a {@linkplain java.lang.ThreadLocal ThreadLocal}
24-
* variable.
28+
* All context aware utility classes in this library are tested
29+
* to make sure they reactivate and close snapshots in a safe way.
2530
*
2631
* <h2>{@linkplain nl.talsmasoftware.context.api.ContextManager}</h2>
2732
* <p>
28-
* Manages the active context.
29-
* Can {@linkplain nl.talsmasoftware.context.api.ContextManager#activate(java.lang.Object) activate a new context}
30-
* and provides access to
31-
* the {@linkplain nl.talsmasoftware.context.api.ContextManager#getActiveContextValue() active context value}.
33+
* Manages {@linkplain nl.talsmasoftware.context.api.Context contexts} by providing a standard way of interacting
34+
* with {@linkplain java.lang.ThreadLocal} values.
3235
*
3336
* <p>
34-
* For normal application code it should not be necessary to interact with context managers directly.
35-
* Instead, using the various context-aware utility classes from the core module will automatically propagate
36-
* any supported context types to background threads for you.
37+
* Managed context values can be accessed via a ContextManager by:
38+
* <ul>
39+
* <li>Calling {@code getActiveContextValue()} which <em>gets</em> the current thread-local value.
40+
* <li>Calling {@code activate(value)} which <em>sets</em> the given value until {@code close()}
41+
* is called on the returned {@code Context}.
42+
* <li>Calling {@code clear()} which <em>removes</em> the thread-local value.
43+
* </ul>
3744
*
38-
* <h2>{@linkplain nl.talsmasoftware.context.api.ContextSnapshot}</h2>
45+
* <h2>{@linkplain nl.talsmasoftware.context.api.Context}</h2>
3946
* <p>
40-
* A snapshot contains the active context value from all known context managers.<br>
41-
* These values can be reactivated all together in another thread
42-
* by {@linkplain nl.talsmasoftware.context.api.ContextSnapshot#reactivate() reactivating} the snapshot.<br>
43-
* Reactivated snapshots <strong>must</strong> be closed to avoid leaking context.
47+
* Abstraction for an activated {@linkplain java.lang.ThreadLocal} value.
4448
*
4549
* <p>
46-
* All context aware utility classes in this the core module of this library are tested
47-
* to make sure they reactivate and close snapshots in a safe way.
50+
* When the context manager {@code activates} a value, a new Context is returned.
51+
* Closing this context will remove the activated value again.
4852
*
4953
* @author Sjoerd Talsma
5054
*/

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ to make sure they reactivate _and_ close snapshots in a safe way.
3636

3737
Manages a [context](#context) by providing a standard way of interacting with `ThreadLocal` values.
3838

39-
Thread-local values can be accessed via a ContextManager by:
39+
Managed thread-local values can be accessed via a ContextManager by:
4040

4141
- Calling `getActiveContextValue()` which _gets_ the current thread-local value.
4242
- Calling `activate(value)` which _sets_ the given value until `close()` is called on the resulting `Context`.

0 commit comments

Comments
 (0)