From 1f153c73ec6d6347b714603a114908ac420ca9d7 Mon Sep 17 00:00:00 2001 From: silvanheller Date: Thu, 13 Oct 2022 15:27:38 +0200 Subject: [PATCH 1/4] respecting config flag, fixes #341 --- .../java/org/vitrivr/cineast/api/Main.java | 24 ++++++++++++------- cineast.json | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java index 8a440025e..9aa32ad96 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java @@ -50,13 +50,21 @@ public static void main(String[] args) { e.printStackTrace(); System.err.println("Failed to initialize Monitoring due to an exception: " + e.getMessage()); } - - /* Start Cineast CLI in interactive mode (blocking). */ - CLI.start(CineastCli.class); - - /* This part is only reached when user enters exit/quit: Stops the Cineast API endpoint. */ - APIEndpoint.stop(); - GRPCEndpoint.stop(); - PrometheusServer.stopServer(); + try { + /* Start Cineast CLI in interactive mode (blocking). */ + if (Config.sharedConfig().getApi().getEnableCli()) { + CLI.start(CineastCli.class); + } else { + while (true) { + Thread.sleep(100); + } + } + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + APIEndpoint.stop(); + GRPCEndpoint.stop(); + PrometheusServer.stopServer(); + } } } diff --git a/cineast.json b/cineast.json index ccbcab07b..c4d54c413 100644 --- a/cineast.json +++ b/cineast.json @@ -85,7 +85,7 @@ }, "api": { - "enableCLI": true, + "enableCLI": false, "enableWebsocket": true, "enableWebsocketSecure": false, "enableRest": true, From 2efe0df9d0fb45798996f08c7115a7d62437fae3 Mon Sep 17 00:00:00 2001 From: silvanheller Date: Thu, 13 Oct 2022 15:53:12 +0200 Subject: [PATCH 2/4] Adding Goodbye-message to indicate finally-loop is running --- cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java index 9aa32ad96..a62f60d30 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java @@ -62,6 +62,7 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } finally { + System.out.println("Goodbye!"); APIEndpoint.stop(); GRPCEndpoint.stop(); PrometheusServer.stopServer(); From b8cfc82725c145d6f79837b0fe3c7ed9d1a397a6 Mon Sep 17 00:00:00 2001 From: silvanheller Date: Thu, 13 Oct 2022 15:57:58 +0200 Subject: [PATCH 3/4] adding shutdown hook --- .../src/main/java/org/vitrivr/cineast/api/Main.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java index a62f60d30..09eacaf69 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java @@ -61,11 +61,13 @@ public static void main(String[] args) { } } catch (InterruptedException e) { e.printStackTrace(); - } finally { - System.out.println("Goodbye!"); + } + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + System.out.println("Shutting down endpoints..."); APIEndpoint.stop(); GRPCEndpoint.stop(); PrometheusServer.stopServer(); - } + System.out.println("Goodbye!"); + })); } } From d66fbbff957f6b81b93058917d2c2740e46f6de5 Mon Sep 17 00:00:00 2001 From: silvanheller Date: Thu, 13 Oct 2022 16:04:59 +0200 Subject: [PATCH 4/4] adding shutdown hook --- .../main/java/org/vitrivr/cineast/api/Main.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java index 09eacaf69..774b55dda 100644 --- a/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java +++ b/cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java @@ -50,6 +50,13 @@ public static void main(String[] args) { e.printStackTrace(); System.err.println("Failed to initialize Monitoring due to an exception: " + e.getMessage()); } + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + System.out.println("Shutting down endpoints..."); + APIEndpoint.stop(); + GRPCEndpoint.stop(); + PrometheusServer.stopServer(); + System.out.println("Goodbye!"); + })); try { /* Start Cineast CLI in interactive mode (blocking). */ if (Config.sharedConfig().getApi().getEnableCli()) { @@ -62,12 +69,5 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - System.out.println("Shutting down endpoints..."); - APIEndpoint.stop(); - GRPCEndpoint.stop(); - PrometheusServer.stopServer(); - System.out.println("Goodbye!"); - })); } }