Skip to content

Commit 3609778

Browse files
Rename context(ContextMap) to setContextMap(ContextMap) and fix some doc strings
1 parent 36bcc82 commit 3609778

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/AsyncContextProvider.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ interface AsyncContextProvider {
4848
ContextMap context();
4949

5050
/**
51-
* Set the {@link ContextMap}.
51+
* Set the async context {@link ContextMap}.
52+
*
53+
* Note that unlike {@link AsyncContextProvider#attachContextMap(ContextMap)}, this method does not provide a
54+
* {@link Scope} to restore the state to what it was previously.
5255
*
5356
* @param context the new value for {@link ContextMap}.
54-
* @return {@code this}.
5557
*/
56-
void context(ContextMap context);
58+
void setContextMap(ContextMap context);
5759

5860
/**
5961
* Attach the {@link ContextMap} to the current local scope.

servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/CopyOnWriteContextMap.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,18 @@ public ContextMap captured() {
194194
return this;
195195
}
196196

197+
// CapturedContext method. For the base async context implementation, attaching means setting the correct
198+
// AsyncContextProvider thread-local to _this_ ContextMap instance.
197199
@Override
198200
public Scope attachContext() {
199201
return AsyncContext.provider().attachContextMap(this);
200202
}
201203

202-
// Scope method
204+
// Scope method. For the base async context implementation, the `prev` map instance is returned as the Scope if that
205+
// is the context state that needs to be restored and restoring just means setting it to the thread-local.
203206
@Override
204207
public void close() {
205-
AsyncContext.provider().context(this);
208+
AsyncContext.provider().setContextMap(this);
206209
}
207210

208211
private interface CopyContextMap {

servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/DefaultAsyncContextProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public final ContextMap context() {
6565
}
6666

6767
@Override
68-
public final void context(ContextMap contextMap) {
68+
public final void setContextMap(ContextMap contextMap) {
6969
final Thread currentThread = Thread.currentThread();
7070
if (currentThread instanceof ContextMapHolder) {
7171
final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;

servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/NoopAsyncContextProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public CapturedContext captureContext(ContextMap contextMap) {
5757
}
5858

5959
@Override
60-
public void context(@Nullable ContextMap contextMap) {
60+
public void setContextMap(@Nullable ContextMap contextMap) {
6161
// noop
6262
}
6363

servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/Scope.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
*/
1616
package io.servicetalk.concurrent.api;
1717

18-
import io.servicetalk.context.api.ContextMap;
19-
2018
/**
2119
* An abstraction for detaching a context from the current thread.
2220
*
2321
* This abstraction is intended to allow the modifications performed by
24-
* {@link AsyncContextProvider#attachContextMap(ContextMap)} to be undone. In practice, this may look like restoring
25-
* a {@link ThreadLocal} to the state it had before the call to
26-
* {@link AsyncContextProvider#attachContextMap(ContextMap)}.
22+
* {@link CapturedContext#attachContext()} to be undone. In practice, this may look like restoring a {@link ThreadLocal}
23+
* to the state it had before the call to {@link CapturedContext#attachContext()}.
2724
*/
2825
interface Scope extends AutoCloseable {
2926

0 commit comments

Comments
 (0)