Skip to content

Commit eb1d94e

Browse files
committed
1 parent 001746b commit eb1d94e

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

modules/commons/src/main/java/org/apache/ignite/internal/thread/context/Context.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717

1818
package org.apache.ignite.internal.thread.context;
1919

20-
/** Represents mapping of {@link ContextAttribute} to their corresponding values with the ability to be attached to the thread. */
20+
/**
21+
* Represents a set of mappings of the {@link ContextAttribute} to its corresponding value. Context provides an ability
22+
* to be attached to the thread, which makes {@link ContextAttribute} values accessible via {@link ContextAttribute#get()}
23+
* method called from the same thread.
24+
*
25+
* @see ContextAttribute
26+
* @see ContextSnapshot
27+
*/
2128
public final class Context {
2229
/**
23-
* Creates a new {@link AttributeValueHolder} with a single mapping of the specified {@link AttributeValueHolder}
24-
* to the specified value. The {@link AttributeValueHolder} can be used to accumulate mappings.
30+
* Creates a new Context with a single mapping of the specified {@link AttributeValueHolder} to its value.
31+
* The returned {@link AttributeValueHolder} represents the last added to the Context mapping and can be used to
32+
* accumulate more mappings of {@link ContextAttribute}s to their values.
2533
*
2634
* @see AttributeValueHolder#with(ContextAttribute, Object)
2735
*/
@@ -54,7 +62,12 @@ private <T> AttributeValueHolder(ContextAttribute<T> attr, T val, AttributeValue
5462
this.val = val;
5563
}
5664

57-
/** Adds a new mapping of the specified attribute to its value to the current {@link ContextDataChain}. */
65+
/**
66+
* Adds to the Context a new mapping of the specified attribute to its value.
67+
*
68+
* @return {@link AttributeValueHolder} instance that represents the last added to the Context mapping and can be
69+
* used to accumulate more mappings of {@link ContextAttribute}s to their values.
70+
*/
5871
public <T> AttributeValueHolder with(ContextAttribute<T> attr, T val) {
5972
return attr.get() == val ? this : new AttributeValueHolder(attr, val, this);
6073
}
@@ -79,9 +92,9 @@ <T> T value() {
7992
}
8093

8194
/**
82-
* Attaches {@link ContextAttribute} values stored in current {@link ContextDataChain} to the thread
83-
* this method is called from. If {@link ContextAttribute} value was already attached for the current thread,
84-
* its value will be stashed and replaced by the new ones.
95+
* Attaches {@link ContextAttribute} values stored in current Context to the thread this method is called from.
96+
* If {@link ContextAttribute} value was already attached for the current thread, its value will be stashed and
97+
* replaced by the new ones.
8598
*
8699
* @return {@link Scope} instance that, when closed, resets the values for all {@link ContextAttribute}s added
87100
* to the current Context and restores them to the previously attached values, if any.

modules/commons/src/main/java/org/apache/ignite/internal/thread/context/ContextSnapshot.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
package org.apache.ignite.internal.thread.context;
1919

20-
/** */
20+
/**
21+
* Represents Snapshot of all {@link ContextAttribute}s and their corresponding values. Note that Snapshot also stores
22+
* the states of {@link ContextAttribute}s for which value are note explicitly specified.
23+
*/
2124
public class ContextSnapshot extends ContextDataChain<ContextSnapshot> {
2225
/** */
2326
static final ContextSnapshot ROOT = new ContextSnapshot();
@@ -37,7 +40,13 @@ private ContextSnapshot(Context.AttributeValueHolder data, ContextSnapshot prev)
3740
this.data = data;
3841
}
3942

40-
/** */
43+
/**
44+
* Stashes all {@link ContextAttribute} values attached to the thread this method is called from and replaces them with
45+
* ones stored in the current Snapshot.
46+
*
47+
* @return {@link Scope} instance that, when closed, restores the values of all {@link ContextAttribute}s to the
48+
* state they were in before the current method was called.
49+
*/
4150
public Scope restore() {
4251
ThreadLocalContextStorage threadData = ThreadLocalContextStorage.get();
4352

@@ -71,7 +80,10 @@ Context.AttributeValueHolder data() {
7180
return this == ROOT;
7281
}
7382

74-
/** */
83+
/**
84+
* Captures Snapshot of all {@link ContextAttribute}s and their corresponding values attached to the thread this
85+
* method is called from.
86+
*/
7587
public static ContextSnapshot capture() {
7688
return ThreadLocalContextStorage.get().snapshot();
7789
}

0 commit comments

Comments
 (0)