Skip to content

Commit

Permalink
Add message to UI if there are other running instances of Polypheny
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Dec 16, 2023
1 parent 8b60b29 commit df5cf73
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
Expand Up @@ -174,8 +174,8 @@ String getStatus() {
}


boolean checkForAnyRunningPolyphenyInstances() {
return Boolean.parseBoolean( executeGet( "/control/checkAnyRunningPolyphenyInstances" ) );
int checkForAnyRunningPolyphenyInstances() {
return Integer.parseInt( executeGet( "/control/checkAnyRunningPolyphenyInstances" ) );
}


Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/polypheny/control/control/Control.java
Expand Up @@ -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;


Expand Down Expand Up @@ -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() ) );
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/polypheny/control/control/ServiceManager.java
Expand Up @@ -1018,6 +1018,18 @@ public static List<Integer> getPidOfRunningPolyphenyInstances() {
}


public static List<Integer> getPidOfOtherRunningPolyphenyInstances() {
if ( SystemUtils.IS_OS_WINDOWS ) {
throw new RuntimeException( "This operation is not supported on Windows" );
}
List<Integer> pids = getPidOfRunningPolyphenyInstances();
if ( polyphenyDbProcess != null ) {
pids.remove( Integer.valueOf( polyphenyDbProcess.getPid() ) );
}
return pids;
}


private static boolean existsLocalBranchWithName( Git git, String branchName ) throws GitAPIException {
List<Ref> branches = git.branchList().call();
for ( Ref ref : branches ) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/polypheny/control/httpinterface/Server.java
Expand Up @@ -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() ),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/static/index.html
Expand Up @@ -29,6 +29,7 @@
<div class="root">
<div class="main">
<h1 class="heading">Polypheny Control</h1>
<h2 id="error-header" style="display: none;"></h2>

<div id="dashboardContent">
<table width="80%" class="dashboard" border="0">
Expand Down
22 changes: 8 additions & 14 deletions src/main/resources/static/script.js
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/static/style.css
Expand Up @@ -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;
Expand Down

0 comments on commit df5cf73

Please sign in to comment.