Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/main/java/org/polypheny/qtf/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
public class Main {

public static void main( String[] args ) {
Main main = new Main();
main.loadLibFuse();
if ( args.length > 0 ) {
String runConsole = args[0];
if ( runConsole.equals( "console" ) ) {
Expand All @@ -34,11 +32,5 @@ public static void main( String[] args ) {
}
}

public void loadLibFuse() {
//see https://github.com/RaiMan/SikuliX1/issues/350
// and https://stackoverflow.com/questions/2370545/how-do-i-make-a-target-library-available-to-my-java-app
System.setProperty( "jna.library.path", QTFConfig.getLibraryPath() );
System.load( QTFConfig.getLibfuse() );
}

}
24 changes: 11 additions & 13 deletions src/main/java/org/polypheny/qtf/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@


import java.io.IOException;
import java.util.ResourceBundle;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -34,26 +36,22 @@ public static void run( String[] args ) {
}

@Override
public void start( Stage primaryStage ) {
public void start( Stage stage ) {
Parent root = null;
FXMLLoader loader = null;
//from https://stackoverflow.com/questions/24254000/how-to-force-anti-aliasing-in-javafx-fonts
System.setProperty( "prism.lcdtext", "false" );
try {
loader = new FXMLLoader( getClass().getResource( "/fxml/sample.fxml" ) );
loader = new FXMLLoader( getClass().getResource( "/fxml/startup.fxml" ) );
loader.setResources(ResourceBundle.getBundle("config"));
root = loader.load();
} catch ( IOException e ) {
log.error( "Could not load fxml", e );
System.exit( 1 );
}
//see https://stackoverflow.com/questions/36981599/fxml-minheight-minwidth-attributs-ignored
primaryStage.setMinWidth( root.minWidth( -1 ) );
primaryStage.setMinHeight( root.minHeight( -1 ) );
primaryStage.setTitle( "Polypheny-DB Query-To-File" );
primaryStage.setScene( new Scene( root ) );
primaryStage.show();
//see https://stackoverflow.com/questions/44439408/javafx-controller-detect-when-stage-is-closing
Controller controller = loader.getController();
primaryStage.setOnHidden( e -> controller.shutdown() );

stage.setMinWidth( root.minWidth( -1 ) );
stage.setMinHeight( root.minHeight( -1 ) );
stage.setTitle( "Edit Settings" );
stage.setScene( new Scene( root ) );
stage.show();
}
}
38 changes: 19 additions & 19 deletions src/main/java/org/polypheny/qtf/QTFConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ public class QTFConfig {
}


public static String getFileUrl( String fileName ) {
return String.format( "http://%s:%s/getFile/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), fileName );
}

public static String getRestInterface( String method ) {
return String.format( "http://%s:%s/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), method );
}

public static String getWebSocketUrl() {
return String.format( "ws://%s:%s/webSocket", prop.getProperty( "host" ), prop.getProperty( "port" ) );
}

public static String getLibraryPath() {
return prop.getProperty( "libraryPath" );
}

public static String getLibfuse() {
return getLibraryPath() + prop.getProperty( "libfuse" );
}
// public static String getFileUrl( String fileName ) {
// return String.format( "http://%s:%s/getFile/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), fileName );
// }
//
// public static String getRestInterface( String method ) {
// return String.format( "http://%s:%s/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), method );
// }
//
// public static String getWebSocketUrl() {
// return String.format( "ws://%s:%s/webSocket", prop.getProperty( "host" ), prop.getProperty( "port" ) );
// }

// public static String getLibraryPath() {
// return prop.getProperty( "libraryPath" );
// }

// public static String getLibfuse() {
// return getLibraryPath() + prop.getProperty( "libfuse" );
// }


public static int getFuseCapacityGB() {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/polypheny/qtf/QueryInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.polypheny.qtf.web.SocketClient;
import org.polypheny.qtf.web.UIRequest.QueryRequest;
import org.polypheny.qtf.web.UIRequest.TableRequest;
import static org.polypheny.qtf.StartUpController.getHost;
import static org.polypheny.qtf.StartUpController.getPortNbr;


@Slf4j
Expand All @@ -54,7 +56,7 @@ public QueryInterface() {
//myFuse.umount();
myFuse.mount( root.toPath(), false, false );
try {
this.socketClient = new SocketClient( new URI( QTFConfig.getWebSocketUrl() ), myFuse, this );
this.socketClient = new SocketClient( new URI( String.format( "ws://%s:%s/webSocket", getHost(), getPortNbr() ) ), myFuse, this );
log.info( "Connecting to websocket..." );
if ( socketClient.connectBlocking() ) {
log.info( "Established a connection with the websocket" );
Expand Down Expand Up @@ -87,7 +89,7 @@ Result commit() {
}
BatchUpdateRequest request = myFuse.getBatchUpdateRequest();
//multiPartContent: see https://github.com/Kong/unirest-java/issues/165
MultipartBody body = Unirest.post( QTFConfig.getRestInterface( "batchUpdate" ) ).multiPartContent();
MultipartBody body = Unirest.post( String.format( "http://%s:%s/%s", getHost(), getPortNbr(), "batchUpdate" ) ).multiPartContent();
int counter = 0;
for ( Update update : request.getUpdates() ) {
for ( Value value : update.getNewValues().values() ) {
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/org/polypheny/qtf/StartUpController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.polypheny.qtf;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

@Slf4j
public class StartUpController implements Initializable {

@FXML
private TextField hostName;
@FXML
private TextField port;
@FXML
private TextField libraryPath;
@FXML
private TextField libfuse;

private static String host;
private static String portNbr;

public StartUpController(){
}

@FXML
public void submit() {
host = hostName.getText();
portNbr = port.getText();

libfuse.getScene().getWindow().hide();
loadLibFuse();

Parent root = null;
FXMLLoader loader = null;
//from https://stackoverflow.com/questions/24254000/how-to-force-anti-aliasing-in-javafx-fonts
System.setProperty( "prism.lcdtext", "false" );
try {
loader = new FXMLLoader( getClass().getResource( "/fxml/sample.fxml" ) );
root = loader.load();
} catch ( IOException e ) {
log.error( "Could not load fxml", e );
System.exit( 1 );
}
Stage primaryStage = new Stage();
//see https://stackoverflow.com/questions/36981599/fxml-minheight-minwidth-attributs-ignored
primaryStage.setMinWidth( root.minWidth( -1 ) );
primaryStage.setMinHeight( root.minHeight( -1 ) );
primaryStage.setTitle( "Polypheny-DB Query-To-File" );
primaryStage.setScene( new Scene( root ) );
primaryStage.show();
//see https://stackoverflow.com/questions/44439408/javafx-controller-detect-when-stage-is-closing
Controller controller = loader.getController();
primaryStage.setOnHidden( e -> controller.shutdown() );
}

public static String getHost() {
return host;
}

public static String getPortNbr() {
return portNbr;
}


public void loadLibFuse() {
//see https://github.com/RaiMan/SikuliX1/issues/350
// and https://stackoverflow.com/questions/2370545/how-do-i-make-a-target-library-available-to-my-java-app
System.setProperty( "jna.library.path", libraryPath.getText() );
System.load( libraryPath.getText() + libfuse.getText() );
}

@Override
public void initialize( URL url, ResourceBundle resourceBundle ) {

}

}
5 changes: 4 additions & 1 deletion src/main/java/org/polypheny/qtf/fuse/ResultFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import ru.serce.jnrfuse.struct.FuseFileInfo;
import ru.serce.jnrfuse.struct.Statvfs;

import static org.polypheny.qtf.StartUpController.getHost;
import static org.polypheny.qtf.StartUpController.getPortNbr;


@Slf4j
//see https://github.com/SerCeMan/jnr-fuse/blob/master/src/main/java/ru/serce/jnrfuse/examples/MemoryFS.java
Expand Down Expand Up @@ -260,7 +263,7 @@ private int read( Pointer buffer, long size, long offset ) {
}

private HttpResponse<byte[]> restRequest( final String fileUrl ) {
return Unirest.get( QTFConfig.getFileUrl( fileUrl ) ).asBytes();
return Unirest.get( String.format( "http://%s:%s/getFile/%s", getHost(), getPortNbr(), fileUrl ) ).asBytes();
}

private synchronized void truncate( long size ) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/resources/fxml/startup.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.layout.HBox?>
<GridPane prefHeight="300" prefWidth="400" alignment="center" hgap="10" vgap="5" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.polypheny.qtf.StartUpController" stylesheets="@../main.css">
<padding><Insets top="25" right="25" bottom="10" left="20"/></padding>

<Text text="Please edit for custom settings" GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="2"/>
<Label text="Host Name:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField id="hostName" fx:id="hostName" text="%host" GridPane.columnIndex="1" GridPane.rowIndex="1"/>

<Label text="Port:" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<TextField id="Port" fx:id="port" text="%port" GridPane.columnIndex="1" GridPane.rowIndex="2"/>

<Label text="Library Path:" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<TextField id="libraryPath" fx:id="libraryPath" text="%libraryPath" GridPane.columnIndex="1" GridPane.rowIndex="3"/>

<Label text="Fuse Library File Name:" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
<TextField id="libfuse" fx:id="libfuse" text="%libfuse" GridPane.columnIndex="1" GridPane.rowIndex="4"/>

<HBox spacing="10" alignment="center" GridPane.columnIndex="1" GridPane.rowIndex="5">
<Button mnemonicParsing="false" onMouseClicked="#submit" text="submit"/>
</HBox>

</GridPane>