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
+
1
5
description = " GraphQL Support for Spring Applications"
2
6
3
7
apply plugin : " kotlin"
4
8
9
+ multiRelease {
10
+ releaseVersions 21
11
+ }
12
+
13
+ configurations {
14
+ java21Api. extendsFrom(api)
15
+ java21Implementation. extendsFrom(implementation)
16
+ }
17
+
5
18
dependencies {
6
19
api ' com.graphql-java:graphql-java'
7
20
api ' io.projectreactor:reactor-core'
@@ -103,3 +116,6 @@ dependencies {
103
116
test {
104
117
useJUnitPlatform()
105
118
}
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 46
46
import reactor .core .publisher .Flux ;
47
47
import reactor .core .publisher .Mono ;
48
48
import reactor .core .scheduler .Scheduler ;
49
- import reactor .core .scheduler .Schedulers ;
50
49
51
50
import org .springframework .aot .hint .annotation .RegisterReflectionForBinding ;
52
51
import org .springframework .graphql .execution .ErrorType ;
52
+ import org .springframework .graphql .execution .ReactorSchedulers ;
53
53
import org .springframework .graphql .execution .SubscriptionPublisherException ;
54
54
import org .springframework .graphql .server .WebGraphQlHandler ;
55
55
import org .springframework .graphql .server .WebGraphQlResponse ;
@@ -484,7 +484,7 @@ private static class SessionState {
484
484
485
485
SessionState (String graphQlSessionId , WebMvcSessionInfo sessionInfo ) {
486
486
this .sessionInfo = sessionInfo ;
487
- this .scheduler = Schedulers . newSingle ("GraphQL-WsSession-" + graphQlSessionId );
487
+ this .scheduler = ReactorSchedulers . singleThread ("GraphQL-WsSession-" + graphQlSessionId );
488
488
this .keepAliveSubscriber = new KeepAliveSubscriber (sessionInfo .getSession ());
489
489
}
490
490
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