|
16 | 16 |
|
17 | 17 | package io.appulse.encon.benchmark; |
18 | 18 |
|
| 19 | +import static java.util.concurrent.TimeUnit.SECONDS; |
| 20 | + |
19 | 21 | import java.io.IOException; |
| 22 | +import java.net.InetAddress; |
20 | 23 | import java.util.concurrent.ExecutorService; |
21 | 24 | import java.util.concurrent.Executors; |
| 25 | +import java.util.concurrent.Future; |
22 | 26 |
|
23 | | -import io.appulse.epmd.java.server.cli.CommonOptions; |
24 | | -import io.appulse.epmd.java.server.command.server.ServerCommandExecutor; |
25 | | -import io.appulse.epmd.java.server.command.server.ServerCommandOptions; |
| 27 | +import io.appulse.epmd.java.server.SubcommandServer; |
26 | 28 | import io.appulse.utils.SocketUtils; |
| 29 | +import lombok.SneakyThrows; |
| 30 | +import lombok.val; |
| 31 | +import lombok.extern.slf4j.Slf4j; |
27 | 32 |
|
28 | 33 | import org.openjdk.jmh.runner.Defaults; |
29 | 34 | import org.openjdk.jmh.runner.NoBenchmarksException; |
|
39 | 44 | * @since 1.6.0 |
40 | 45 | * @author Artem Labazin |
41 | 46 | */ |
| 47 | +@Slf4j |
42 | 48 | public class Main { |
43 | 49 |
|
44 | 50 | private static ExecutorService executor; |
45 | 51 |
|
46 | | - private static ServerCommandExecutor server; |
| 52 | + private static Future<?> future; |
47 | 53 |
|
48 | 54 | public static void main(String[] argv) throws RunnerException, IOException { |
49 | 55 | try { |
@@ -111,24 +117,35 @@ public static void main(String[] argv) throws RunnerException, IOException { |
111 | 117 | } |
112 | 118 | } |
113 | 119 |
|
| 120 | + @SneakyThrows |
114 | 121 | private static void startEpmd () { |
115 | 122 | if (!SocketUtils.isPortAvailable(4369)) { |
116 | 123 | return; |
117 | 124 | } |
118 | 125 | executor = Executors.newSingleThreadExecutor(); |
119 | 126 |
|
120 | | - ServerCommandOptions options = new ServerCommandOptions(); |
121 | | - options.setChecks(true); |
| 127 | + val server = SubcommandServer.builder() |
| 128 | + .port(SocketUtils.findFreePort().orElseThrow(RuntimeException::new)) |
| 129 | + .ip(InetAddress.getByName("0.0.0.0")) |
| 130 | + .build(); |
122 | 131 |
|
123 | | - server = new ServerCommandExecutor(new CommonOptions(), options); |
124 | | - executor.execute(server::execute); |
| 132 | + future = executor.submit(() -> { |
| 133 | + try { |
| 134 | + server.run(); |
| 135 | + } catch (Throwable ex) { |
| 136 | + log.error("popa", ex); |
| 137 | + } |
| 138 | + }); |
| 139 | + SECONDS.sleep(1); |
125 | 140 | } |
126 | 141 |
|
127 | 142 | private static void stopEpmd () { |
128 | 143 | if (executor == null) { |
129 | 144 | return; |
130 | 145 | } |
131 | | - server.close(); |
| 146 | + if (future != null) { |
| 147 | + future.cancel(true); |
| 148 | + } |
132 | 149 | executor.shutdown(); |
133 | 150 | } |
134 | 151 | } |
0 commit comments