snazy commented on code in PR #18:
URL: https://github.com/apache/polaris-tools/pull/18#discussion_r2084007507


##########
apprunner/common/src/main/java/org/apache/polaris/apprunner/common/ListenUrlWaiter.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.apprunner.common;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
+import java.util.function.LongSupplier;
+import java.util.regex.Pattern;
+
+/**
+ * Accepts {@link String}s via it's {@link #accept(String)} method and checks 
for the {@code
+ * Listening on: http...} pattern.
+ */
+final class ListenUrlWaiter implements Consumer<String> {
+
+  private static final Pattern HTTP_PORT_LOG_PATTERN =
+      Pattern.compile(
+          "^.*Listening on: (http[s]?://[^ ]*)([.] Management interface 
listening on (http[s]?://[^ ]*)[.])?$");
+  static final String TIMEOUT_MESSAGE =
+      "Did not get the http(s) listen URL from the console output.";
+  private static final long MAX_ITER_WAIT_NANOS = 
TimeUnit.MILLISECONDS.toNanos(50);
+  public static final String NOTHING_RECEIVED = " No output received from 
process.";
+  public static final String CAPTURED_LOG_FOLLOWS = " Captured output 
follows:\n";
+
+  private final LongSupplier clock;
+  private final Consumer<String> stdoutTarget;
+  private final long deadlineListenUrl;
+
+  private final CompletableFuture<List<String>> listenUrl = new 
CompletableFuture<>();
+  private final List<String> capturedLog = new ArrayList<>();
+
+  /**
+   * Construct a new instance to wait for Quarkus' {@code Listening on: ...} 
message.
+   *
+   * @param clock monotonic clock, nanoseconds
+   * @param timeToListenUrlMillis timeout in millis, the "Listen on: ..." must 
be received within
+   *     this time (otherwise it will fail)
+   * @param stdoutTarget "real" target for "stdout"
+   */
+  ListenUrlWaiter(LongSupplier clock, long timeToListenUrlMillis, 
Consumer<String> stdoutTarget) {
+    this.clock = clock;
+    this.stdoutTarget = stdoutTarget;
+    this.deadlineListenUrl =
+        clock.getAsLong() + 
TimeUnit.MILLISECONDS.toNanos(timeToListenUrlMillis);
+  }
+
+  @Override
+  public void accept(String line) {
+    if (!listenUrl.isDone()) {
+      synchronized (capturedLog) {
+        capturedLog.add(line);

Review Comment:
   It's not a problem in practice. But you want to see all output in case the 
startup fails. So yes, it's for debugging when things don't work right w/ 
"_your_" server.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to