diff options
Diffstat (limited to 'subprojects')
6 files changed, 12 insertions, 89 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/ProblemWebModule.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/ProblemWebModule.java index 12e39e55..b0197c01 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/ProblemWebModule.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/ProblemWebModule.java | |||
@@ -9,13 +9,11 @@ | |||
9 | */ | 9 | */ |
10 | package tools.refinery.language.web; | 10 | package tools.refinery.language.web; |
11 | 11 | ||
12 | import org.eclipse.xtext.ide.ExecutorServiceProvider; | ||
13 | import org.eclipse.xtext.web.server.XtextServiceDispatcher; | 12 | import org.eclipse.xtext.web.server.XtextServiceDispatcher; |
14 | import org.eclipse.xtext.web.server.model.IWebDocumentProvider; | 13 | import org.eclipse.xtext.web.server.model.IWebDocumentProvider; |
15 | import org.eclipse.xtext.web.server.model.XtextWebDocumentAccess; | 14 | import org.eclipse.xtext.web.server.model.XtextWebDocumentAccess; |
16 | import org.eclipse.xtext.web.server.occurrences.OccurrencesService; | 15 | import org.eclipse.xtext.web.server.occurrences.OccurrencesService; |
17 | import tools.refinery.language.web.occurrences.ProblemOccurrencesService; | 16 | import tools.refinery.language.web.occurrences.ProblemOccurrencesService; |
18 | import tools.refinery.language.web.xtext.VirtualThreadExecutorServiceProvider; | ||
19 | import tools.refinery.language.web.xtext.server.push.PushServiceDispatcher; | 17 | import tools.refinery.language.web.xtext.server.push.PushServiceDispatcher; |
20 | import tools.refinery.language.web.xtext.server.push.PushWebDocumentAccess; | 18 | import tools.refinery.language.web.xtext.server.push.PushWebDocumentAccess; |
21 | import tools.refinery.language.web.xtext.server.push.PushWebDocumentProvider; | 19 | import tools.refinery.language.web.xtext.server.push.PushWebDocumentProvider; |
@@ -39,8 +37,4 @@ public class ProblemWebModule extends AbstractProblemWebModule { | |||
39 | public Class<? extends OccurrencesService> bindOccurrencesService() { | 37 | public Class<? extends OccurrencesService> bindOccurrencesService() { |
40 | return ProblemOccurrencesService.class; | 38 | return ProblemOccurrencesService.class; |
41 | } | 39 | } |
42 | |||
43 | public Class<? extends ExecutorServiceProvider> bindExecutorServiceProvider() { | ||
44 | return VirtualThreadExecutorServiceProvider.class; | ||
45 | } | ||
46 | } | 40 | } |
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java index 1924f661..ad19e77d 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/ServerLauncher.java | |||
@@ -19,6 +19,7 @@ import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletConta | |||
19 | import org.eclipse.jetty.server.Server; | 19 | import org.eclipse.jetty.server.Server; |
20 | import org.eclipse.jetty.util.resource.Resource; | 20 | import org.eclipse.jetty.util.resource.Resource; |
21 | import org.eclipse.jetty.util.resource.ResourceFactory; | 21 | import org.eclipse.jetty.util.resource.ResourceFactory; |
22 | import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
22 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
23 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
24 | import tools.refinery.language.web.config.BackendConfigServlet; | 25 | import tools.refinery.language.web.config.BackendConfigServlet; |
@@ -49,7 +50,8 @@ public class ServerLauncher { | |||
49 | private final Server server; | 50 | private final Server server; |
50 | 51 | ||
51 | public ServerLauncher(InetSocketAddress bindAddress, String[] allowedOrigins, String webSocketUrl) { | 52 | public ServerLauncher(InetSocketAddress bindAddress, String[] allowedOrigins, String webSocketUrl) { |
52 | server = VirtualThreadUtils.newServerWithVirtualThreadsThreadPool("jetty", bindAddress); | 53 | server = new Server(bindAddress); |
54 | ((QueuedThreadPool) server.getThreadPool()).setName("jetty"); | ||
53 | var handler = new ServletContextHandler(); | 55 | var handler = new ServletContextHandler(); |
54 | addSessionHandler(handler); | 56 | addSessionHandler(handler); |
55 | addProblemServlet(handler, allowedOrigins); | 57 | addProblemServlet(handler, allowedOrigins); |
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/VirtualThreadUtils.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/VirtualThreadUtils.java deleted file mode 100644 index 27802e0c..00000000 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/VirtualThreadUtils.java +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.language.web; | ||
7 | |||
8 | import org.eclipse.jetty.server.Server; | ||
9 | import org.eclipse.jetty.server.ServerConnector; | ||
10 | import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
11 | import org.eclipse.jetty.util.thread.ThreadPool; | ||
12 | |||
13 | import java.net.InetSocketAddress; | ||
14 | import java.time.Duration; | ||
15 | import java.util.concurrent.ExecutorService; | ||
16 | import java.util.concurrent.Executors; | ||
17 | |||
18 | public final class VirtualThreadUtils { | ||
19 | private VirtualThreadUtils() { | ||
20 | throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); | ||
21 | } | ||
22 | |||
23 | public static ExecutorService newNamedVirtualThreadsExecutor(String name) { | ||
24 | // Based on | ||
25 | // https://github.com/eclipse/jetty.project/blob/83154b4ffe4767ef44981598d6c26e6a5d32e57c/jetty-server/src/main/config/etc/jetty-threadpool-virtual-preview.xml | ||
26 | return Executors.newThreadPerTaskExecutor(Thread.ofVirtual() | ||
27 | .allowSetThreadLocals(true) | ||
28 | .inheritInheritableThreadLocals(false) | ||
29 | .name(name + "-virtual-", 0) | ||
30 | .factory()); | ||
31 | } | ||
32 | |||
33 | public static ThreadPool newThreadPoolWithVirtualThreadsExecutor(String name) { | ||
34 | // Based on | ||
35 | // https://github.com/eclipse/jetty.project/blob/83154b4ffe4767ef44981598d6c26e6a5d32e57c/jetty-server/src/main/config/etc/jetty-threadpool-virtual-preview.xml | ||
36 | int timeout = (int) Duration.ofMinutes(1).toMillis(); | ||
37 | var threadPool = new QueuedThreadPool(200, 10, timeout, -1, null, null); | ||
38 | threadPool.setName(name); | ||
39 | threadPool.setDetailedDump(false); | ||
40 | threadPool.setVirtualThreadsExecutor(newNamedVirtualThreadsExecutor(name)); | ||
41 | return threadPool; | ||
42 | } | ||
43 | |||
44 | public static Server newServerWithVirtualThreadsThreadPool(String name, InetSocketAddress listenAddress) { | ||
45 | var server = new Server(newThreadPoolWithVirtualThreadsExecutor(name)); | ||
46 | var connector = new ServerConnector(server); | ||
47 | try { | ||
48 | connector.setHost(listenAddress.getHostName()); | ||
49 | connector.setPort(listenAddress.getPort()); | ||
50 | server.addConnector(connector); | ||
51 | } catch (Exception e) { | ||
52 | connector.close(); | ||
53 | throw e; | ||
54 | } | ||
55 | return server; | ||
56 | } | ||
57 | } | ||
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/VirtualThreadExecutorServiceProvider.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/VirtualThreadExecutorServiceProvider.java deleted file mode 100644 index 699a09ab..00000000 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/VirtualThreadExecutorServiceProvider.java +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.language.web.xtext; | ||
7 | |||
8 | import org.eclipse.xtext.ide.ExecutorServiceProvider; | ||
9 | import tools.refinery.language.web.VirtualThreadUtils; | ||
10 | |||
11 | import java.util.concurrent.ExecutorService; | ||
12 | |||
13 | public class VirtualThreadExecutorServiceProvider extends ExecutorServiceProvider { | ||
14 | private static final String THREAD_POOL_NAME = "xtextWeb"; | ||
15 | |||
16 | @Override | ||
17 | protected ExecutorService createInstance(String key) { | ||
18 | var name = key == null ? THREAD_POOL_NAME : THREAD_POOL_NAME + "-" + key; | ||
19 | return VirtualThreadUtils.newNamedVirtualThreadsExecutor(name); | ||
20 | } | ||
21 | } | ||
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java index 53a757eb..40f5281d 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java | |||
@@ -17,9 +17,13 @@ import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletConta | |||
17 | import org.eclipse.jetty.http.HttpHeader; | 17 | import org.eclipse.jetty.http.HttpHeader; |
18 | import org.eclipse.jetty.http.HttpStatus; | 18 | import org.eclipse.jetty.http.HttpStatus; |
19 | import org.eclipse.jetty.server.Server; | 19 | import org.eclipse.jetty.server.Server; |
20 | import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
20 | import org.eclipse.xtext.testing.GlobalRegistries; | 21 | import org.eclipse.xtext.testing.GlobalRegistries; |
21 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; | 22 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; |
22 | import org.junit.jupiter.api.*; | 23 | import org.junit.jupiter.api.AfterEach; |
24 | import org.junit.jupiter.api.BeforeEach; | ||
25 | import org.junit.jupiter.api.Test; | ||
26 | import org.junit.jupiter.api.TestInfo; | ||
23 | import org.junit.jupiter.params.ParameterizedTest; | 27 | import org.junit.jupiter.params.ParameterizedTest; |
24 | import org.junit.jupiter.params.provider.ValueSource; | 28 | import org.junit.jupiter.params.provider.ValueSource; |
25 | import tools.refinery.language.web.tests.WebSocketIntegrationTestClient; | 29 | import tools.refinery.language.web.tests.WebSocketIntegrationTestClient; |
@@ -193,7 +197,8 @@ class ProblemWebSocketServletIntegrationTest { | |||
193 | private void startServer(String allowedOrigins) { | 197 | private void startServer(String allowedOrigins) { |
194 | var testName = getClass().getSimpleName() + "-" + testInfo.getDisplayName(); | 198 | var testName = getClass().getSimpleName() + "-" + testInfo.getDisplayName(); |
195 | var listenAddress = new InetSocketAddress(HOSTNAME, serverPort); | 199 | var listenAddress = new InetSocketAddress(HOSTNAME, serverPort); |
196 | server = VirtualThreadUtils.newServerWithVirtualThreadsThreadPool(testName, listenAddress); | 200 | server = new Server(listenAddress); |
201 | ((QueuedThreadPool) server.getThreadPool()).setName(testName); | ||
197 | var handler = new ServletContextHandler(); | 202 | var handler = new ServletContextHandler(); |
198 | var holder = new ServletHolder(ProblemWebSocketServlet.class); | 203 | var holder = new ServletHolder(ProblemWebSocketServlet.class); |
199 | if (allowedOrigins != null) { | 204 | if (allowedOrigins != null) { |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java index 630549d4..52acee6d 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/AwaitTerminationExecutorServiceProvider.java | |||
@@ -6,14 +6,14 @@ | |||
6 | package tools.refinery.language.web.tests; | 6 | package tools.refinery.language.web.tests; |
7 | 7 | ||
8 | import com.google.inject.Singleton; | 8 | import com.google.inject.Singleton; |
9 | import tools.refinery.language.web.xtext.VirtualThreadExecutorServiceProvider; | 9 | import org.eclipse.xtext.ide.ExecutorServiceProvider; |
10 | 10 | ||
11 | import java.util.ArrayList; | 11 | import java.util.ArrayList; |
12 | import java.util.List; | 12 | import java.util.List; |
13 | import java.util.concurrent.ExecutorService; | 13 | import java.util.concurrent.ExecutorService; |
14 | 14 | ||
15 | @Singleton | 15 | @Singleton |
16 | public class AwaitTerminationExecutorServiceProvider extends VirtualThreadExecutorServiceProvider { | 16 | public class AwaitTerminationExecutorServiceProvider extends ExecutorServiceProvider { |
17 | private final List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); | 17 | private final List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); |
18 | 18 | ||
19 | @Override | 19 | @Override |