|
1 | 1 | package redis.embedded; |
2 | 2 |
|
3 | | -import redis.embedded.util.CheckedRunnable; |
4 | | - |
5 | 3 | import java.io.File; |
6 | 4 | import java.io.IOException; |
7 | | -import java.util.Arrays; |
8 | 5 | import java.util.Collections; |
9 | 6 | import java.util.List; |
10 | 7 | import java.util.function.Consumer; |
@@ -43,25 +40,23 @@ public synchronized void start() throws IOException { |
43 | 40 | .directory(new File(args.get(0)).getParentFile()) |
44 | 41 | .start(); |
45 | 42 | addShutdownHook("RedisInstanceCleaner", checkedToRuntime(this::stop)); |
46 | | - final String startupLog = awaitServerReady(process, readyPattern); |
47 | | - if (soutListener != null) { |
48 | | - soutListener.accept(startupLog); |
49 | | - newDaemonThread(() -> logStream(process.getInputStream(), soutListener)).start(); |
50 | | - } |
51 | 43 | if (serrListener != null) |
52 | 44 | newDaemonThread(() -> logStream(process.getErrorStream(), serrListener)).start(); |
| 45 | + awaitServerReady(process, readyPattern, soutListener); |
| 46 | + if (soutListener != null) |
| 47 | + newDaemonThread(() -> logStream(process.getInputStream(), soutListener)).start(); |
53 | 48 |
|
54 | 49 | active = true; |
55 | 50 | } catch (final IOException e) { |
56 | 51 | throw new IOException("Failed to start Redis service", e); |
57 | 52 | } |
58 | 53 | } |
59 | 54 |
|
60 | | - private static String awaitServerReady(final Process process, final Pattern readyPattern) throws IOException { |
| 55 | + private static void awaitServerReady(final Process process, final Pattern readyPattern, |
| 56 | + final Consumer<String> soutListener) throws IOException { |
61 | 57 | final StringBuilder log = new StringBuilder(); |
62 | | - if (!findMatchInStream(process.getInputStream(), readyPattern, log)) |
| 58 | + if (!findMatchInStream(process.getInputStream(), readyPattern, soutListener, log)) |
63 | 59 | throw new IOException("Ready pattern not found in log. Startup log: " + log); |
64 | | - return log.toString(); |
65 | 60 | } |
66 | 61 |
|
67 | 62 | public synchronized void stop() throws IOException { |
|
0 commit comments