|
15 | 15 | */ |
16 | 16 | package io.netty5.microbench.util; |
17 | 17 |
|
| 18 | +import io.netty5.util.concurrent.AbstractEventExecutor; |
18 | 19 | import io.netty5.util.concurrent.DefaultThreadFactory; |
| 20 | +import io.netty5.util.concurrent.EventExecutor; |
| 21 | +import io.netty5.util.concurrent.FastThreadLocalThread; |
| 22 | +import io.netty5.util.concurrent.Future; |
19 | 23 | import io.netty5.util.internal.SystemPropertyUtil; |
| 24 | +import io.netty5.util.internal.ThreadExecutorMap; |
20 | 25 | import org.openjdk.jmh.annotations.Fork; |
21 | 26 | import org.openjdk.jmh.runner.options.ChainedOptionsBuilder; |
22 | 27 | import org.slf4j.Logger; |
23 | 28 | import org.slf4j.LoggerFactory; |
24 | 29 |
|
| 30 | +import java.util.concurrent.Callable; |
25 | 31 | import java.util.concurrent.LinkedBlockingQueue; |
26 | 32 | import java.util.concurrent.ThreadPoolExecutor; |
27 | 33 | import java.util.concurrent.TimeUnit; |
@@ -35,11 +41,78 @@ public class AbstractMicrobenchmark extends AbstractMicrobenchmarkBase { |
35 | 41 | protected static final int DEFAULT_FORKS = 2; |
36 | 42 |
|
37 | 43 | public static final class HarnessExecutor extends ThreadPoolExecutor { |
38 | | - private final Logger logger = LoggerFactory.getLogger(AbstractMicrobenchmark.class); |
| 44 | + |
| 45 | + private static final Logger logger = LoggerFactory.getLogger(AbstractMicrobenchmark.class); |
39 | 46 |
|
40 | 47 | public HarnessExecutor(int maxThreads, String prefix) { |
41 | 48 | super(maxThreads, maxThreads, 0, TimeUnit.MILLISECONDS, |
42 | | - new LinkedBlockingQueue<>(), new DefaultThreadFactory(prefix)); |
| 49 | + new LinkedBlockingQueue<Runnable>(), |
| 50 | + new DefaultThreadFactory(prefix)); |
| 51 | + EventExecutor eventExecutor = new AbstractEventExecutor() { |
| 52 | + |
| 53 | + @Override |
| 54 | + public Future<Void> schedule(Runnable task, long delay, TimeUnit unit) { |
| 55 | + throw new UnsupportedOperationException(); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public <V> Future<V> schedule(Callable<V> task, long delay, TimeUnit unit) { |
| 60 | + throw new UnsupportedOperationException(); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public Future<Void> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit) { |
| 65 | + throw new UnsupportedOperationException(); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public Future<Void> scheduleWithFixedDelay( |
| 70 | + Runnable task, long initialDelay, long delay, TimeUnit unit) { |
| 71 | + throw new UnsupportedOperationException(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public boolean inEventLoop(Thread thread) { |
| 76 | + return thread instanceof FastThreadLocalThread; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public boolean isShuttingDown() { |
| 81 | + throw new UnsupportedOperationException(); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public Future<Void> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit) { |
| 86 | + throw new UnsupportedOperationException(); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public Future<Void> terminationFuture() { |
| 91 | + throw new UnsupportedOperationException(); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public boolean isShutdown() { |
| 96 | + throw new UnsupportedOperationException(); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public boolean isTerminated() { |
| 101 | + throw new UnsupportedOperationException(); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { |
| 106 | + throw new UnsupportedOperationException(); |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public void execute(Runnable command) { |
| 111 | + throw new UnsupportedOperationException(); |
| 112 | + } |
| 113 | + }; |
| 114 | + setThreadFactory(ThreadExecutorMap.apply(getThreadFactory(), eventExecutor)); |
| 115 | + |
43 | 116 | logger.debug("Using harness executor"); |
44 | 117 | } |
45 | 118 | } |
|