Skip to content

Commit cc61c4b

Browse files
committed
Rename ContextManager to ReactorContextManager
1 parent 212392d commit cc61c4b

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed

spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ private ContextDataFetcherDecorator(DataFetcher<?> delegate, boolean subscriptio
5959

6060
@Override
6161
public Object get(DataFetchingEnvironment environment) throws Exception {
62-
ContextView contextView = ContextManager.getReactorContext(environment);
62+
ContextView contextView = ReactorContextManager.getReactorContext(environment);
6363

6464
Object value;
6565
try {
66-
ContextManager.restoreThreadLocalValues(contextView);
66+
ReactorContextManager.restoreThreadLocalValues(contextView);
6767
value = this.delegate.get(environment);
6868
}
6969
finally {
70-
ContextManager.resetThreadLocalValues(contextView);
70+
ReactorContextManager.resetThreadLocalValues(contextView);
7171
}
7272

7373
if (this.subscription) {

spring-graphql/src/main/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
/**
3939
* {@link DataFetcherExceptionHandler} that invokes {@link DataFetcherExceptionResolver}'s
40-
* in a sequence until one returns a non-null list of {@link GraphQLError}'s.
40+
* in a sequence until one returns a list of {@link GraphQLError}'s.
4141
*
4242
* @author Rossen Stoyanchev
4343
*/
@@ -75,7 +75,7 @@ DataFetcherExceptionHandlerResult invokeChain(Throwable ex, DataFetchingEnvironm
7575
.map((errors) -> DataFetcherExceptionHandlerResult.newResult().errors(errors).build())
7676
.switchIfEmpty(Mono.fromCallable(() -> applyDefaultHandling(ex, env)))
7777
.contextWrite((context) -> {
78-
ContextView contextView = ContextManager.getReactorContext(env);
78+
ContextView contextView = ReactorContextManager.getReactorContext(env);
7979
return (contextView.isEmpty() ? context : context.putAll(contextView));
8080
})
8181
.toFuture()
@@ -92,13 +92,13 @@ DataFetcherExceptionHandlerResult invokeChain(Throwable ex, DataFetchingEnvironm
9292
private Mono<List<GraphQLError>> resolveErrors(
9393
Throwable ex, DataFetchingEnvironment environment, DataFetcherExceptionResolver resolver) {
9494

95-
ContextView contextView = ContextManager.getReactorContext(environment);
95+
ContextView contextView = ReactorContextManager.getReactorContext(environment);
9696
try {
97-
ContextManager.restoreThreadLocalValues(contextView);
97+
ReactorContextManager.restoreThreadLocalValues(contextView);
9898
return resolver.resolveException(ex, environment);
9999
}
100100
finally {
101-
ContextManager.resetThreadLocalValues(contextView);
101+
ReactorContextManager.resetThreadLocalValues(contextView);
102102
}
103103
}
104104

spring-graphql/src/main/java/org/springframework/graphql/execution/ExecutionGraphQlService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import org.springframework.graphql.RequestInput;
2626

2727
/**
28-
* Implementation of {@link GraphQlService} that performs GraphQL request execution
29-
* through {@link GraphQL#executeAsync(ExecutionInput)}.
28+
* {@link GraphQlService} that uses a {@link GraphQlSource} to obtain a
29+
* {@link GraphQL} instance and perform query execution.
3030
*
3131
* @author Rossen Stoyanchev
3232
* @since 1.0.0
@@ -44,7 +44,7 @@ public Mono<ExecutionResult> execute(RequestInput input) {
4444
ExecutionInput executionInput = input.toExecutionInput();
4545
GraphQL graphQl = this.graphQlSource.graphQl();
4646
return Mono.deferContextual((contextView) -> {
47-
ContextManager.setReactorContext(contextView, executionInput);
47+
ReactorContextManager.setReactorContext(contextView, executionInput);
4848
return Mono.fromFuture(graphQl.executeAsync(executionInput));
4949
});
5050
}

spring-graphql/src/main/java/org/springframework/graphql/execution/ContextManager.java renamed to spring-graphql/src/main/java/org/springframework/graphql/execution/ReactorContextManager.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@
2828
import org.springframework.lang.Nullable;
2929

3030
/**
31-
* Package private utility class for propagating a Reactor {@link ContextView} through the
32-
* {@link ExecutionInput} and the {@link DataFetchingEnvironment} of a request.
31+
* Provides helper methods to save Reactor context in the {@link ExecutionInput}
32+
* so it can be subsequently obtained from {@link DataFetchingEnvironment} and
33+
* propagated to data fetchers or exception handlers.
34+
*
35+
* <p>The Reactor context is also used to carry ThreadLocal values that are also
36+
* restored around the execution of data fetchers and exceptions handlers.
3337
*
3438
* @author Rossen Stoyanchev
3539
* @since 1.0.0
3640
*/
37-
public abstract class ContextManager {
41+
public abstract class ReactorContextManager {
3842

39-
private static final String CONTEXT_VIEW_KEY = ContextManager.class.getName() + ".CONTEXT_VIEW";
43+
private static final String CONTEXT_VIEW_KEY = ReactorContextManager.class.getName() + ".CONTEXT_VIEW";
4044

41-
private static final String THREAD_ID = ContextManager.class.getName() + ".THREAD_ID";
45+
private static final String THREAD_ID = ReactorContextManager.class.getName() + ".THREAD_ID";
4246

43-
private static final String THREAD_LOCAL_VALUES_KEY = ContextManager.class.getName() + ".THREAD_VALUES_ACCESSOR";
47+
private static final String THREAD_LOCAL_VALUES_KEY = ReactorContextManager.class.getName() + ".THREAD_VALUES_ACCESSOR";
4448

45-
private static final String THREAD_LOCAL_ACCESSOR_KEY = ContextManager.class.getName() + ".THREAD_LOCAL_ACCESSOR";
49+
private static final String THREAD_LOCAL_ACCESSOR_KEY = ReactorContextManager.class.getName() + ".THREAD_LOCAL_ACCESSOR";
4650

4751
/**
4852
* Save the given Reactor {@link ContextView} in the an {@link ExecutionInput} for

spring-graphql/src/main/java/org/springframework/graphql/web/DefaultWebGraphQlHandlerBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import reactor.core.publisher.Mono;
2525

2626
import org.springframework.graphql.GraphQlService;
27-
import org.springframework.graphql.execution.ContextManager;
27+
import org.springframework.graphql.execution.ReactorContextManager;
2828
import org.springframework.graphql.execution.ThreadLocalAccessor;
2929
import org.springframework.lang.Nullable;
3030
import org.springframework.util.Assert;
@@ -115,7 +115,7 @@ private static class ThreadLocalExtractingHandler implements WebGraphQlHandler {
115115
@Override
116116
public Mono<WebOutput> handle(WebInput input) {
117117
return this.delegate.handle(input).contextWrite((context) ->
118-
ContextManager.extractThreadLocalValues(this.accessor, context));
118+
ReactorContextManager.extractThreadLocalValues(this.accessor, context));
119119
}
120120

121121
}

spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void monoDataFetcher() throws Exception {
5151
}));
5252

5353
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
54-
ContextManager.setReactorContext(Context.of("name", "007"), input);
54+
ReactorContextManager.setReactorContext(Context.of("name", "007"), input);
5555

5656
Map<String, Object> data = graphQl.executeAsync(input).get().getData();
5757

@@ -67,7 +67,7 @@ void fluxDataFetcher() throws Exception {
6767
})));
6868

6969
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greetings }").build();
70-
ContextManager.setReactorContext(Context.of("name", "007"), input);
70+
ReactorContextManager.setReactorContext(Context.of("name", "007"), input);
7171

7272
Map<String, Object> data = graphQl.executeAsync(input).get().getData();
7373

@@ -85,7 +85,7 @@ void fluxDataFetcherSubscription() throws Exception {
8585
})));
8686

8787
ExecutionInput input = ExecutionInput.newExecutionInput().query("subscription { greetings }").build();
88-
ContextManager.setReactorContext(Context.of("name", "007"), input);
88+
ReactorContextManager.setReactorContext(Context.of("name", "007"), input);
8989

9090
Publisher<String> publisher = graphQl.executeAsync(input).get().getData();
9191

@@ -109,8 +109,8 @@ void dataFetcherWithThreadLocalContext() {
109109
(env) -> "Hello " + nameThreadLocal.get());
110110

111111
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
112-
ContextView view = ContextManager.extractThreadLocalValues(accessor, Context.empty());
113-
ContextManager.setReactorContext(view, input);
112+
ContextView view = ReactorContextManager.extractThreadLocalValues(accessor, Context.empty());
113+
ReactorContextManager.setReactorContext(view, input);
114114

115115
ExecutionResult result = Mono.delay(Duration.ofMillis(10))
116116
.flatMap((aLong) -> Mono.fromFuture(graphQl.executeAsync(input)))

spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void resolveExceptionWithReactorContext() throws Exception {
7878
.errorType(ErrorType.BAD_REQUEST).build()))));
7979

8080
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
81-
ContextManager.setReactorContext(Context.of("name", "007"), input);
81+
ReactorContextManager.setReactorContext(Context.of("name", "007"), input);
8282

8383
ExecutionResult result = graphQl.executeAsync(input).get();
8484

@@ -103,8 +103,8 @@ void resolveExceptionWithThreadLocal() {
103103
.build()));
104104

105105
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
106-
ContextView view = ContextManager.extractThreadLocalValues(accessor, Context.empty());
107-
ContextManager.setReactorContext(view, input);
106+
ContextView view = ReactorContextManager.extractThreadLocalValues(accessor, Context.empty());
107+
ReactorContextManager.setReactorContext(view, input);
108108

109109
ExecutionResult result = Mono.delay(Duration.ofMillis(10))
110110
.flatMap((aLong) -> Mono.fromFuture(graphQl.executeAsync(input)))

spring-graphql/src/test/java/org/springframework/graphql/execution/ContextManagerTests.java renamed to spring-graphql/src/test/java/org/springframework/graphql/execution/ReactorContextManagerTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@
2626
import static org.assertj.core.api.Assertions.assertThat;
2727

2828
/**
29-
* Unit tests for {@link ContextManager}.
29+
* Unit tests for {@link ReactorContextManager}.
3030
* @author Rossen Stoyanchev
3131
*/
32-
public class ContextManagerTests {
32+
public class ReactorContextManagerTests {
3333

3434
@Test
3535
void restoreThreadLocaValues() {
3636
ThreadLocal<String> threadLocal = new ThreadLocal<>();
3737
threadLocal.set("myValue");
3838

39-
Context context = ContextManager.extractThreadLocalValues(
39+
Context context = ReactorContextManager.extractThreadLocalValues(
4040
new TestThreadLocalAccessor<>(threadLocal), Context.empty());
4141
try {
4242
Mono.delay(Duration.ofMillis(10))
4343
.doOnNext(aLong -> {
4444
assertThat(threadLocal.get()).isNull();
45-
ContextManager.restoreThreadLocalValues(context);
45+
ReactorContextManager.restoreThreadLocalValues(context);
4646
assertThat(threadLocal.get()).isEqualTo("myValue");
47-
ContextManager.resetThreadLocalValues(context);
47+
ReactorContextManager.resetThreadLocalValues(context);
4848
})
4949
.block();
5050
}
@@ -58,15 +58,15 @@ void restoreThreadLocaValuesOnSameThreadIsNoOp() {
5858
ThreadLocal<String> threadLocal = new ThreadLocal<>();
5959
threadLocal.set("myValue");
6060

61-
Context context = ContextManager.extractThreadLocalValues(
61+
Context context = ReactorContextManager.extractThreadLocalValues(
6262
new TestThreadLocalAccessor<>(threadLocal, true), Context.empty());
6363

6464
threadLocal.remove();
65-
ContextManager.restoreThreadLocalValues(context);
65+
ReactorContextManager.restoreThreadLocalValues(context);
6666
assertThat(threadLocal.get()).isNull();
6767

6868
threadLocal.set("anotherValue");
69-
ContextManager.resetThreadLocalValues(context);
69+
ReactorContextManager.resetThreadLocalValues(context);
7070
assertThat(threadLocal.get()).isEqualTo("anotherValue");
7171
}
7272

0 commit comments

Comments
 (0)