From df5cf737af4df7732626d7193f165802191423d4 Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sat, 16 Dec 2023 20:33:07 +0100 Subject: [PATCH] Add message to UI if there are other running instances of Polypheny --- .../client/PolyphenyControlConnector.java | 4 ++-- .../polypheny/control/control/Control.java | 10 +++++++++ .../control/control/ServiceManager.java | 12 ++++++++++ .../control/httpinterface/Server.java | 7 ++++++ src/main/resources/static/index.html | 1 + src/main/resources/static/script.js | 22 +++++++------------ src/main/resources/static/style.css | 9 ++++++++ 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java b/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java index bd388a7..89f047c 100644 --- a/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java +++ b/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java @@ -174,8 +174,8 @@ String getStatus() { } - boolean checkForAnyRunningPolyphenyInstances() { - return Boolean.parseBoolean( executeGet( "/control/checkAnyRunningPolyphenyInstances" ) ); + int checkForAnyRunningPolyphenyInstances() { + return Integer.parseInt( executeGet( "/control/checkAnyRunningPolyphenyInstances" ) ); } diff --git a/src/main/java/org/polypheny/control/control/Control.java b/src/main/java/org/polypheny/control/control/Control.java index 4ca48c8..5fbe9eb 100644 --- a/src/main/java/org/polypheny/control/control/Control.java +++ b/src/main/java/org/polypheny/control/control/Control.java @@ -33,6 +33,7 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import lombok.NonNull; +import org.apache.commons.lang3.SystemUtils; import org.polypheny.control.httpinterface.ClientCommunicationStream; @@ -163,6 +164,15 @@ public void checkAnyRunningPolyphenyInstances( Context ctx ) { } + public int getNumberOfOtherRunningPolyphenyInstances() { + if ( !SystemUtils.IS_OS_WINDOWS ) { + return ServiceManager.getPidOfOtherRunningPolyphenyInstances().size(); + } else { + return -1; + } + } + + public void getVersion( Context ctx ) { ctx.result( gson.toJson( ServiceManager.getVersion() ) ); } diff --git a/src/main/java/org/polypheny/control/control/ServiceManager.java b/src/main/java/org/polypheny/control/control/ServiceManager.java index 021299f..02d37ea 100644 --- a/src/main/java/org/polypheny/control/control/ServiceManager.java +++ b/src/main/java/org/polypheny/control/control/ServiceManager.java @@ -1018,6 +1018,18 @@ public static List getPidOfRunningPolyphenyInstances() { } + public static List getPidOfOtherRunningPolyphenyInstances() { + if ( SystemUtils.IS_OS_WINDOWS ) { + throw new RuntimeException( "This operation is not supported on Windows" ); + } + List pids = getPidOfRunningPolyphenyInstances(); + if ( polyphenyDbProcess != null ) { + pids.remove( Integer.valueOf( polyphenyDbProcess.getPid() ) ); + } + return pids; + } + + private static boolean existsLocalBranchWithName( Git git, String branchName ) throws GitAPIException { List branches = git.branchList().call(); for ( Ref ref : branches ) { diff --git a/src/main/java/org/polypheny/control/httpinterface/Server.java b/src/main/java/org/polypheny/control/httpinterface/Server.java index ec79e51..a087f18 100644 --- a/src/main/java/org/polypheny/control/httpinterface/Server.java +++ b/src/main/java/org/polypheny/control/httpinterface/Server.java @@ -171,6 +171,13 @@ public Server( Control control, int port ) { 5, TimeUnit.SECONDS ); + // For switching background color when there are other polypheny instances running on this host + exec.scheduleAtFixedRate( + () -> ClientRegistry.broadcast( "numberOfOtherRunningPolyphenyInstances", "" + control.getNumberOfOtherRunningPolyphenyInstances() ), + 0, + 5, + TimeUnit.SECONDS ); + // Periodically sent versions to clients exec.scheduleAtFixedRate( () -> ClientRegistry.broadcast( "version", ServiceManager.getVersion() ), diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 6cf41c5..4e21c75 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -29,6 +29,7 @@

Polypheny Control

+
diff --git a/src/main/resources/static/script.js b/src/main/resources/static/script.js index d425067..8d8040c 100644 --- a/src/main/resources/static/script.js +++ b/src/main/resources/static/script.js @@ -81,6 +81,14 @@ webSocket.onmessage = function (msg) { $( "body" ).css( "background-color", "#3B83C8" ); } } + if ( data.hasOwnProperty( "numberOfOtherRunningPolyphenyInstances" ) ) { // Periodically sent by server to keep the connection open + if ( data["numberOfOtherRunningPolyphenyInstances"] > 0 ) { + $( '#error-header' ).show(); + $( '#error-header' ).html( "There are other running instances of Polypheny on this host!" ); + } else { + $( '#error-header' ).hide(); + } + } if ( data.hasOwnProperty( "version" ) ) { // Periodically sent by server to keep the connection open var pdbString = "PDB: " + data["version"]["pdb-branch"] + " @ " + data["version"]["pdb-commit"].substring( 0, 7 ); var puiString = "PUI: " + data["version"]["pui-branch"] + " @ " + data["version"]["pui-commit"].substring( 0, 7 ); @@ -444,20 +452,6 @@ $( document ).ready( function () { // Update version getControlVersion(); -// Change bg color -$( document ).on( 'keyup', function ( e ) { - if ( debug ) { - console.log( $( "body" ).css( "background-color" ) ); - } - if ( e.which === 112 && $( "body" ).css( "background-color" ) !== "rgb(128, 128, 128)" ) { - if ( $( "body" ).css( "background-color" ) === "rgb(165, 215, 210)" ) { - $( 'body' ).css( 'background-color', "#3B83C8" ); - } else { - $('body').css('background-color', "#A5D7D2"); - } - } -}); - // Initial adjust on page load window.onload = adjustFooterPosition; $(document).ready(function() { diff --git a/src/main/resources/static/style.css b/src/main/resources/static/style.css index 6540dde..ba70b50 100644 --- a/src/main/resources/static/style.css +++ b/src/main/resources/static/style.css @@ -114,6 +114,15 @@ body { margin-top: 0; } +#error-header { + text-align: center; + font-family: sans-serif; + font-size: min(2.5vw, 40px); + margin-bottom: 2.5vh; + margin-top: 0; + color: #d40418; +} + .content { margin-left: auto; margin-right: auto;