@@ -486,39 +486,40 @@ different thread.
486
486
487
487
Spring for GraphQL supports propagating `ThreadLocal` values from the Servlet container
488
488
thread to the thread a `DataFetcher` and other components invoked by GraphQL Java to
489
- execute on. To do this, an application needs to create a `ThreadLocalAccessor` to extract
490
- `ThreadLocal` values of interest:
489
+ execute on. To do this, an application needs to implement
490
+ `io.micrometer.context.ThreadLocalAccessor` for a ` ThreadLocal` values of interest:
491
491
492
492
[source,java,indent=0,subs="verbatim,quotes"]
493
493
----
494
- public class RequestAttributesAccessor implements ThreadLocalAccessor {
494
+ public class RequestAttributesAccessor implements ThreadLocalAccessor<RequestAttributes> {
495
495
496
- private static final String KEY = RequestAttributesAccessor.class.getName();
496
+ @Override
497
+ public Object key() {
498
+ return RequestAttributesAccessor.class.getName();
499
+ }
497
500
498
- @Override
499
- public void extractValues(Map<String, Object> container ) {
500
- container.put(KEY, RequestContextHolder.getRequestAttributes() );
501
- }
501
+ @Override
502
+ public RequestAttributes getValue( ) {
503
+ return RequestContextHolder.getRequestAttributes();
504
+ }
502
505
503
- @Override
504
- public void restoreValues(Map<String, Object> values) {
505
- if (values.containsKey(KEY)) {
506
- RequestContextHolder.setRequestAttributes((RequestAttributes) values.get(KEY));
507
- }
508
- }
506
+ @Override
507
+ public void setValue(RequestAttributes attributes) {
508
+ RequestContextHolder.setRequestAttributes(attributes);
509
+ }
509
510
510
- @Override
511
- public void resetValues(Map<String, Object> values ) {
512
- RequestContextHolder.resetRequestAttributes();
513
- }
511
+ @Override
512
+ public void reset( ) {
513
+ RequestContextHolder.resetRequestAttributes();
514
+ }
514
515
515
516
}
516
517
----
517
518
518
- A `ThreadLocalAccessor` can be registered in the <<server-interception,WebGraphHandler>>
519
- builder. The Boot starter detects beans of this type and automatically registers them for
520
- Spring MVC application, see the
521
- {spring-boot-ref-docs}/web.html#web.graphql.transports.http-websocket[Web Endpoints] section .
519
+ You can register a `ThreadLocalAccessor` manually on startup with the global
520
+ `ContextRegistry` instance, which is accessible via
521
+ `io.micrometer.context.ContextRegistry#getInstance()`. You can also register it
522
+ automatically through the `java.util.ServiceLoader` mechanism .
522
523
523
524
524
525
[[execution-context-webflux]]
0 commit comments