File tree Expand file tree Collapse file tree 6 files changed +155
-2
lines changed
java21/org/springframework/graphql/execution
java/org/springframework/graphql
test/java21/org/springframework/graphql/execution Expand file tree Collapse file tree 6 files changed +155
-2
lines changed Original file line number Diff line number Diff line change 1+ plugins {
2+ id ' org.springframework.graphql.multiReleaseJar'
3+ }
4+
15description = " GraphQL Support for Spring Applications"
26
37apply plugin : " kotlin"
48
9+ multiRelease {
10+ releaseVersions 21
11+ }
12+
13+ configurations {
14+ java21Api. extendsFrom(api)
15+ java21Implementation. extendsFrom(implementation)
16+ }
17+
518dependencies {
619 api ' com.graphql-java:graphql-java'
720 api ' io.projectreactor:reactor-core'
@@ -103,3 +116,6 @@ dependencies {
103116test {
104117 useJUnitPlatform()
105118}
119+ java21Test {
120+ useJUnitPlatform()
121+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .graphql .execution ;
18+
19+ import reactor .core .scheduler .Scheduler ;
20+ import reactor .core .scheduler .Schedulers ;
21+
22+ /**
23+ * Factory for Reactor {@link Scheduler schedulers}.
24+ * @author Brian Clozel
25+ * @since 2.0.0
26+ */
27+ public abstract class ReactorSchedulers {
28+
29+ /**
30+ * Create a scheduler backed by a single new thread, using {@link Schedulers#newSingle(String)} on Java < 21
31+ * and a custom Virtual Thread factory on Java >= 21.
32+ * @param name component and thread name prefix
33+ */
34+ public static Scheduler singleThread (String name ) {
35+ return Schedulers .newSingle (name );
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 4646import reactor .core .publisher .Flux ;
4747import reactor .core .publisher .Mono ;
4848import reactor .core .scheduler .Scheduler ;
49- import reactor .core .scheduler .Schedulers ;
5049
5150import org .springframework .aot .hint .annotation .RegisterReflectionForBinding ;
5251import org .springframework .graphql .execution .ErrorType ;
52+ import org .springframework .graphql .execution .ReactorSchedulers ;
5353import org .springframework .graphql .execution .SubscriptionPublisherException ;
5454import org .springframework .graphql .server .WebGraphQlHandler ;
5555import org .springframework .graphql .server .WebGraphQlResponse ;
@@ -484,7 +484,7 @@ private static class SessionState {
484484
485485 SessionState (String graphQlSessionId , WebMvcSessionInfo sessionInfo ) {
486486 this .sessionInfo = sessionInfo ;
487- this .scheduler = Schedulers . newSingle ("GraphQL-WsSession-" + graphQlSessionId );
487+ this .scheduler = ReactorSchedulers . singleThread ("GraphQL-WsSession-" + graphQlSessionId );
488488 this .keepAliveSubscriber = new KeepAliveSubscriber (sessionInfo .getSession ());
489489 }
490490
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .graphql .execution ;
18+
19+ import reactor .core .scheduler .Scheduler ;
20+ import reactor .core .scheduler .Schedulers ;
21+
22+ /**
23+ * Factory for Reactor {@link Scheduler schedulers}.
24+ * @author Brian Clozel
25+ * @since 2.0.0
26+ */
27+ public abstract class ReactorSchedulers {
28+
29+ /**
30+ * Create a scheduler backed by a single new thread, using {@link Schedulers#newSingle(String)} on Java < 21
31+ * and a custom Virtual Thread factory on Java >= 21.
32+ * @param name component and thread name prefix
33+ */
34+ public static Scheduler singleThread (String name ) {
35+ return Schedulers .newSingle (Thread .ofVirtual ().name (name ).factory ());
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2020-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ /**
18+ * Support for GraphQL request execution, including abstractions to configure and invoke
19+ * {@code graphql.GraphQL}.
20+ */
21+ @ NullMarked
22+ package org .springframework .graphql .execution ;
23+
24+ import org .jspecify .annotations .NullMarked ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .springframework .graphql .execution ;
18+
19+ import org .junit .jupiter .api .Test ;
20+ import reactor .core .Disposable ;
21+ import reactor .core .scheduler .Scheduler ;
22+
23+ import static org .assertj .core .api .Assertions .assertThat ;
24+ import static org .awaitility .Awaitility .await ;
25+
26+ class ReactorSchedulersTests {
27+
28+ @ Test
29+ void singleThreadReturnsVirtualThread () {
30+ Scheduler scheduler = ReactorSchedulers .singleThread ("testThread" );
31+ scheduler .init ();
32+ Disposable disposable = scheduler .schedule (() -> assertThat (Thread .currentThread ().isVirtual ()).isTrue ());
33+ await ().until (disposable ::isDisposed );
34+ scheduler .dispose ();
35+ }
36+
37+ }
You can’t perform that action at this time.
0 commit comments