|
| 1 | +/* |
| 2 | + * Copyright 2026 The Netty VirtualThread Scheduler Project |
| 3 | + * |
| 4 | + * The Netty VirtualThread Scheduler Project licenses this file to you under the Apache License, |
| 5 | + * version 2.0 (the "License"); you may not use this file except in compliance with the |
| 6 | + * License. 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 distributed under the |
| 11 | + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 12 | + * either express or implied. See the License for the specific language governing permissions |
| 13 | + * and limitations under the License. |
| 14 | + */ |
| 15 | +package io.netty.loom; |
| 16 | + |
| 17 | +import io.netty.channel.IoEventLoop; |
| 18 | +import io.netty.channel.IoHandlerFactory; |
| 19 | +import io.netty.channel.MultiThreadIoEventLoopGroup; |
| 20 | + |
| 21 | +import java.util.concurrent.Executor; |
| 22 | +import java.util.concurrent.ThreadFactory; |
| 23 | + |
| 24 | +public class VirtualMultithreadManualIoEventLoopGroup extends MultiThreadIoEventLoopGroup { |
| 25 | + |
| 26 | + private ThreadFactory threadFactory; |
| 27 | + |
| 28 | + public VirtualMultithreadManualIoEventLoopGroup(int nThreads, IoHandlerFactory factory) { |
| 29 | + super(nThreads, (Executor) null, factory); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + protected IoEventLoop newChild(Executor executor, IoHandlerFactory ioHandlerFactory, Object... args) { |
| 34 | + if (threadFactory == null) { |
| 35 | + threadFactory = Thread.ofVirtual().factory(); |
| 36 | + } |
| 37 | + var manualTask = new ManualIoEventLoopTask(this, null, ioHandlerFactory); |
| 38 | + var newThread = threadFactory.newThread(manualTask); |
| 39 | + manualTask.setOwningThread(newThread); |
| 40 | + newThread.start(); |
| 41 | + return manualTask; |
| 42 | + } |
| 43 | +} |
0 commit comments