Remove LoggingService and RequestManagerFactory from Services and make fully static

This commit is contained in:
Rohit Awate 2018-08-01 17:04:28 +05:30
parent 22973d1c95
commit 45b757c7c8
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
19 changed files with 106 additions and 122 deletions

View file

@ -30,9 +30,6 @@ import javafx.stage.Stage;
public class Main extends Application { public class Main extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
Services.start();
Services.startServicesThread.join();
SettingsLoader settingsLoader = new SettingsLoader(); SettingsLoader settingsLoader = new SettingsLoader();
settingsLoader.settingsLoaderThread.join(); settingsLoader.settingsLoaderThread.join();

View file

@ -20,7 +20,7 @@ import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
import com.rohitawate.everest.controllers.codearea.highlighters.HighlighterFactory; import com.rohitawate.everest.controllers.codearea.highlighters.HighlighterFactory;
import com.rohitawate.everest.controllers.state.ComposerState; import com.rohitawate.everest.controllers.state.ComposerState;
import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.misc.ThemeManager;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
@ -98,7 +98,7 @@ public class BodyTabController implements Initializable {
urlTab.setContent(formTabContent); urlTab.setContent(formTabContent);
urlTabController = loader.getController(); urlTabController = loader.getController();
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not load URL tab.", e, LocalDateTime.now()); LoggingService.logSevere("Could not load URL tab.", e, LocalDateTime.now());
} }
} }

View file

@ -26,6 +26,7 @@ import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.exceptions.RedirectException; import com.rohitawate.everest.exceptions.RedirectException;
import com.rohitawate.everest.exceptions.UnreliableResponseException; import com.rohitawate.everest.exceptions.UnreliableResponseException;
import com.rohitawate.everest.format.FormatterFactory; import com.rohitawate.everest.format.FormatterFactory;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.misc.ThemeManager;
import com.rohitawate.everest.models.requests.DELETERequest; import com.rohitawate.everest.models.requests.DELETERequest;
@ -34,6 +35,7 @@ import com.rohitawate.everest.models.requests.GETRequest;
import com.rohitawate.everest.models.responses.EverestResponse; import com.rohitawate.everest.models.responses.EverestResponse;
import com.rohitawate.everest.requestmanager.DataDispatchRequestManager; import com.rohitawate.everest.requestmanager.DataDispatchRequestManager;
import com.rohitawate.everest.requestmanager.RequestManager; import com.rohitawate.everest.requestmanager.RequestManager;
import com.rohitawate.everest.requestmanager.RequestManagersFactory;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty; import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
@ -135,7 +137,7 @@ public class DashboardController implements Initializable {
bodyTabController = bodyTabLoader.getController(); bodyTabController = bodyTabLoader.getController();
bodyTab.setContent(bodyTabContent); bodyTab.setContent(bodyTabContent);
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not load headers/body tabs.", e, LocalDateTime.now()); LoggingService.logSevere("Could not load headers/body tabs.", e, LocalDateTime.now());
} }
snackbar = new JFXSnackbar(dashboard); snackbar = new JFXSnackbar(dashboard);
@ -181,7 +183,7 @@ public class DashboardController implements Initializable {
FormatterFactory.getHighlighter(type), FormatterFactory.getHighlighter(type),
HighlighterFactory.getHighlighter(type)); HighlighterFactory.getHighlighter(type));
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now()); LoggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
} }
return; return;
@ -241,7 +243,7 @@ public class DashboardController implements Initializable {
getRequest.setTarget(address); getRequest.setTarget(address);
getRequest.setHeaders(headerTabController.getHeaders()); getRequest.setHeaders(headerTabController.getHeaders());
requestManager = Services.pool.get(); requestManager = RequestManagersFactory.get();
requestManager.setRequest(getRequest); requestManager.setRequest(getRequest);
break; break;
case "POST": case "POST":
@ -286,7 +288,7 @@ public class DashboardController implements Initializable {
dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED); dataRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
} }
requestManager = Services.pool.data(); requestManager = RequestManagersFactory.data();
requestManager.setRequest(dataRequest); requestManager.setRequest(dataRequest);
break; break;
case "DELETE": case "DELETE":
@ -296,7 +298,7 @@ public class DashboardController implements Initializable {
deleteRequest.setTarget(address); deleteRequest.setTarget(address);
deleteRequest.setHeaders(headerTabController.getHeaders()); deleteRequest.setHeaders(headerTabController.getHeaders());
requestManager = Services.pool.delete(); requestManager = RequestManagersFactory.delete();
requestManager.setRequest(deleteRequest); requestManager.setRequest(deleteRequest);
break; break;
default: default:
@ -310,7 +312,7 @@ public class DashboardController implements Initializable {
showLayer(ResponseLayer.PROMPT); showLayer(ResponseLayer.PROMPT);
snackbar.show("Invalid address. Please verify and try again.", 3000); snackbar.show("Invalid address. Please verify and try again.", 3000);
} catch (Exception E) { } catch (Exception E) {
Services.loggingService.logSevere("Request execution failed.", E, LocalDateTime.now()); LoggingService.logSevere("Request execution failed.", E, LocalDateTime.now());
showLayer(ResponseLayer.ERROR); showLayer(ResponseLayer.ERROR);
errorTitle.setText("Oops... That's embarrassing!"); errorTitle.setText("Oops... That's embarrassing!");
errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work."); errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
@ -322,7 +324,7 @@ public class DashboardController implements Initializable {
showLayer(ResponseLayer.ERROR); showLayer(ResponseLayer.ERROR);
Throwable throwable = requestManager.getException(); Throwable throwable = requestManager.getException();
Exception exception = (Exception) throwable; Exception exception = (Exception) throwable;
Services.loggingService.logWarning(httpMethodBox.getValue() + " request could not be processed.", exception, LocalDateTime.now()); LoggingService.logWarning(httpMethodBox.getValue() + " request could not be processed.", exception, LocalDateTime.now());
if (throwable.getClass() == UnreliableResponseException.class) { if (throwable.getClass() == UnreliableResponseException.class) {
UnreliableResponseException URE = (UnreliableResponseException) throwable; UnreliableResponseException URE = (UnreliableResponseException) throwable;
@ -470,7 +472,7 @@ public class DashboardController implements Initializable {
try { try {
Desktop.getDesktop().browse(new URI(addressField.getText())); Desktop.getDesktop().browse(new URI(addressField.getText()));
} catch (Exception ex) { } catch (Exception ex) {
Services.loggingService.logWarning("Invalid URL encountered while opening in browser.", ex, LocalDateTime.now()); LoggingService.logWarning("Invalid URL encountered while opening in browser.", ex, LocalDateTime.now());
} }
}).start(); }).start();
}); });
@ -491,7 +493,7 @@ public class DashboardController implements Initializable {
} catch (Exception e) { } catch (Exception e) {
String errorMessage = "Response could not be parsed."; String errorMessage = "Response could not be parsed.";
snackbar.show(errorMessage, 5000); snackbar.show(errorMessage, 5000);
Services.loggingService.logSevere(errorMessage, e, LocalDateTime.now()); LoggingService.logSevere(errorMessage, e, LocalDateTime.now());
errorTitle.setText("Parsing Error"); errorTitle.setText("Parsing Error");
errorDetails.setText(errorMessage); errorDetails.setText(errorMessage);
showLayer(ResponseLayer.ERROR); showLayer(ResponseLayer.ERROR);
@ -597,7 +599,7 @@ public class DashboardController implements Initializable {
}); });
paramsBox.getChildren().add(headerField); paramsBox.getChildren().add(headerField);
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not append params field.", e, LocalDateTime.now()); LoggingService.logSevere("Could not append params field.", e, LocalDateTime.now());
} }
} }
@ -778,7 +780,7 @@ public class DashboardController implements Initializable {
} }
if (!validMethod) { if (!validMethod) {
Services.loggingService.logInfo("Application state file was tampered with. State could not be recovered.", LocalDateTime.now()); LoggingService.logInfo("Application state file was tampered with. State could not be recovered.", LocalDateTime.now());
return; return;
} }

View file

@ -17,7 +17,7 @@
package com.rohitawate.everest.controllers; package com.rohitawate.everest.controllers;
import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.misc.ThemeManager;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty; import javafx.beans.property.IntegerProperty;
@ -109,7 +109,7 @@ public class FormDataTabController implements Initializable {
}); });
fieldsBox.getChildren().add(fileField); fieldsBox.getChildren().add(fileField);
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not add file field.", e, LocalDateTime.now()); LoggingService.logSevere("Could not add file field.", e, LocalDateTime.now());
} }
} }
@ -161,7 +161,7 @@ public class FormDataTabController implements Initializable {
}); });
fieldsBox.getChildren().add(stringField); fieldsBox.getChildren().add(stringField);
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not add string field.", e, LocalDateTime.now()); LoggingService.logSevere("Could not add string field.", e, LocalDateTime.now());
} }
} }

View file

@ -17,7 +17,7 @@
package com.rohitawate.everest.controllers; package com.rohitawate.everest.controllers;
import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.misc.ThemeManager;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty; import javafx.beans.property.IntegerProperty;
@ -102,7 +102,7 @@ public class HeaderTabController implements Initializable {
}); });
headersBox.getChildren().add(headerField); headersBox.getChildren().add(headerField);
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not add string field.", e, LocalDateTime.now()); LoggingService.logSevere("Could not add string field.", e, LocalDateTime.now());
} }
} }

View file

@ -19,7 +19,7 @@ package com.rohitawate.everest.controllers;
import com.rohitawate.everest.controllers.search.Searchable; import com.rohitawate.everest.controllers.search.Searchable;
import com.rohitawate.everest.controllers.state.ComposerState; import com.rohitawate.everest.controllers.state.ComposerState;
import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.logging.LoggingService;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -76,7 +76,7 @@ public class HistoryItemController implements Initializable, Searchable<Composer
if (comparisonString.contains(searchString)) if (comparisonString.contains(searchString))
return 9; return 9;
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Services.loggingService.logInfo("Failed to parse URL while calculating relativity index.", LocalDateTime.now()); LoggingService.logInfo("Failed to parse URL while calculating relativity index.", LocalDateTime.now());
} }
// Checks if matches with HTTP method // Checks if matches with HTTP method

View file

@ -19,9 +19,9 @@ package com.rohitawate.everest.controllers;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.rohitawate.everest.controllers.state.ComposerState; import com.rohitawate.everest.controllers.state.ComposerState;
import com.rohitawate.everest.controllers.state.DashboardState; import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.KeyMap; import com.rohitawate.everest.misc.KeyMap;
import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.misc.ThemeManager;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.Observable; import javafx.beans.Observable;
@ -222,9 +222,9 @@ public class HomeWindowController implements Initializable {
try { try {
File stateFile = new File("Everest/config/state.json"); File stateFile = new File("Everest/config/state.json");
EverestUtilities.jsonMapper.writeValue(stateFile, composerStates); EverestUtilities.jsonMapper.writeValue(stateFile, composerStates);
Services.loggingService.logInfo("Application state saved.", LocalDateTime.now()); LoggingService.logInfo("Application state saved.", LocalDateTime.now());
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Failed to save application state.", e, LocalDateTime.now()); LoggingService.logSevere("Failed to save application state.", e, LocalDateTime.now());
} }
} }
@ -233,7 +233,7 @@ public class HomeWindowController implements Initializable {
File stateFile = new File("Everest/config/state.json"); File stateFile = new File("Everest/config/state.json");
if (!stateFile.exists()) { if (!stateFile.exists()) {
Services.loggingService.logInfo("Application state file not found. Loading default state.", LocalDateTime.now()); LoggingService.logInfo("Application state file not found. Loading default state.", LocalDateTime.now());
addTab(); addTab();
return; return;
} }
@ -251,10 +251,10 @@ public class HomeWindowController implements Initializable {
addTab(); addTab();
} }
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logWarning("Application state file is either corrupted or outdated. State recovery failed. Loading default state.", e, LocalDateTime.now()); LoggingService.logWarning("Application state file is either corrupted or outdated. State recovery failed. Loading default state.", e, LocalDateTime.now());
addTab(); addTab();
} finally { } finally {
Services.loggingService.logInfo("Application loaded.", LocalDateTime.now()); LoggingService.logInfo("Application loaded.", LocalDateTime.now());
} }
} }

View file

@ -17,7 +17,7 @@
package com.rohitawate.everest.controllers; package com.rohitawate.everest.controllers;
import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.ThemeManager; import com.rohitawate.everest.misc.ThemeManager;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty; import javafx.beans.property.IntegerProperty;
@ -102,7 +102,7 @@ public class URLTabController implements Initializable {
}); });
fieldsBox.getChildren().add(stringField); fieldsBox.getChildren().add(stringField);
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not add string field.", e, LocalDateTime.now()); LoggingService.logSevere("Could not add string field.", e, LocalDateTime.now());
} }
} }

View file

@ -46,7 +46,7 @@ class Visualizer extends ScrollPane {
private void populate(TreeItem<HBox> rootItem, String rootName, JsonNode root) { private void populate(TreeItem<HBox> rootItem, String rootName, JsonNode root) {
if (rootName.equals("root")) { if (rootName.equals("root")) {
this.visualizer.setRoot(rootItem); visualizer.setRoot(rootItem);
} }
Label rootLabel = new Label(rootName); Label rootLabel = new Label(rootName);
@ -117,6 +117,6 @@ class Visualizer extends ScrollPane {
} }
public void clear() { public void clear() {
this.visualizer.setRoot(null); visualizer.setRoot(null);
} }
} }

View file

@ -17,6 +17,7 @@
package com.rohitawate.everest.controllers.search; package com.rohitawate.everest.controllers.search;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.misc.Services;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Task; import javafx.concurrent.Task;
@ -116,12 +117,12 @@ public abstract class SearchablePaneController<T> implements Initializable {
for (T state : entries) for (T state : entries)
addHistoryItem(state); addHistoryItem(state);
} catch (InterruptedException | ExecutionException E) { } catch (InterruptedException | ExecutionException E) {
Services.loggingService.logSevere("Task thread interrupted while populating HistoryTab.", E, LoggingService.logSevere("Task thread interrupted while populating HistoryTab.", E,
LocalDateTime.now()); LocalDateTime.now());
} }
}); });
entryLoader.setOnFailed(e -> Services.loggingService.logWarning("Failed to load history.", entryLoader.setOnFailed(e -> LoggingService.logWarning("Failed to load history.",
(Exception) entryLoader.getException(), LocalDateTime.now())); (Exception) entryLoader.getException(), LocalDateTime.now()));
Services.singleExecutor.execute(entryLoader); Services.singleExecutor.execute(entryLoader);
@ -149,7 +150,7 @@ public abstract class SearchablePaneController<T> implements Initializable {
return searchEntry.getSearchable(); return searchEntry.getSearchable();
} catch (IOException e) { } catch (IOException e) {
Services.loggingService.logSevere("Could not append HistoryItem to list.", e, LocalDateTime.now()); LoggingService.logSevere("Could not append HistoryItem to list.", e, LocalDateTime.now());
} }
return null; return null;

View file

@ -21,7 +21,7 @@ import com.rohitawate.everest.controllers.DashboardController.ResponseLayer;
import com.rohitawate.everest.controllers.DashboardController.ResponseTab; import com.rohitawate.everest.controllers.DashboardController.ResponseTab;
import com.rohitawate.everest.exceptions.RedirectException; import com.rohitawate.everest.exceptions.RedirectException;
import com.rohitawate.everest.exceptions.UnreliableResponseException; import com.rohitawate.everest.exceptions.UnreliableResponseException;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.models.requests.EverestRequest; import com.rohitawate.everest.models.requests.EverestRequest;
import com.rohitawate.everest.models.responses.EverestResponse; import com.rohitawate.everest.models.responses.EverestResponse;
import com.rohitawate.everest.requestmanager.DataDispatchRequestManager; import com.rohitawate.everest.requestmanager.DataDispatchRequestManager;
@ -104,7 +104,7 @@ public class DashboardState {
this.visibleResponseLayer = ResponseLayer.ERROR; this.visibleResponseLayer = ResponseLayer.ERROR;
Throwable throwable = requestManager.getException(); Throwable throwable = requestManager.getException();
Exception exception = (Exception) throwable; Exception exception = (Exception) throwable;
Services.loggingService.logWarning(this.composer.httpMethod + " request could not be processed.", exception, LocalDateTime.now()); LoggingService.logWarning(this.composer.httpMethod + " request could not be processed.", exception, LocalDateTime.now());
if (throwable.getClass() == UnreliableResponseException.class) { if (throwable.getClass() == UnreliableResponseException.class) {
UnreliableResponseException URE = (UnreliableResponseException) throwable; UnreliableResponseException URE = (UnreliableResponseException) throwable;
@ -124,7 +124,7 @@ public class DashboardState {
requestManager.restart(); requestManager.restart();
return; return;
} catch (MalformedURLException MURLE) { } catch (MalformedURLException MURLE) {
Services.loggingService.logInfo("Invalid URL: " + this.composer.target, LocalDateTime.now()); LoggingService.logInfo("Invalid URL: " + this.composer.target, LocalDateTime.now());
} }
} else { } else {
errorTitle = "Oops... That's embarrassing!"; errorTitle = "Oops... That's embarrassing!";

View file

@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.rohitawate.everest.controllers.state.ComposerState; import com.rohitawate.everest.controllers.state.ComposerState;
import com.rohitawate.everest.controllers.state.FieldState; import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.Services; import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.settings.Settings; import com.rohitawate.everest.settings.Settings;
@ -50,7 +51,7 @@ public class HistoryManager {
initDatabase(); initDatabase();
} catch (Exception E) { } catch (Exception E) {
Services.loggingService.logSevere("Exception while initializing HistoryManager.", E, LocalDateTime.now()); LoggingService.logSevere("Exception while initializing HistoryManager.", E, LocalDateTime.now());
} finally { } finally {
System.out.println("Connected to database."); System.out.println("Connected to database.");
} }
@ -89,7 +90,7 @@ public class HistoryManager {
statement.execute(); statement.execute();
} }
// Method is made synchronized to allow only one database transaction at a time. // Method is synchronized to allow only one database transaction at a time.
/** /**
* Saves the request to the database if it is not identical to one made exactly before it. * Saves the request to the database if it is not identical to one made exactly before it.
@ -172,7 +173,7 @@ public class HistoryManager {
history.add(state); history.add(state);
} }
} catch (SQLException e) { } catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); LoggingService.logWarning("Database error.", e, LocalDateTime.now());
} }
return history; return history;
} }
@ -196,7 +197,7 @@ public class HistoryManager {
headers.add(new FieldState(key, value, checked)); headers.add(new FieldState(key, value, checked));
} }
} catch (SQLException e) { } catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); LoggingService.logWarning("Database error.", e, LocalDateTime.now());
} }
return headers; return headers;
} }
@ -229,7 +230,7 @@ public class HistoryManager {
tuples.add(new FieldState(key, value, checked)); tuples.add(new FieldState(key, value, checked));
} }
} catch (SQLException e) { } catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); LoggingService.logWarning("Database error.", e, LocalDateTime.now());
} }
return tuples; return tuples;
@ -318,7 +319,7 @@ public class HistoryManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); LoggingService.logWarning("Database error.", e, LocalDateTime.now());
} catch (NullPointerException NPE) { } catch (NullPointerException NPE) {
/* /*
NPE is thrown by containsKey indicating that the key is not present in the database thereby NPE is thrown by containsKey indicating that the key is not present in the database thereby
@ -418,7 +419,7 @@ public class HistoryManager {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); LoggingService.logWarning("Database error.", e, LocalDateTime.now());
} }
} }
@ -436,7 +437,7 @@ public class HistoryManager {
statement.executeUpdate(); statement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now()); LoggingService.logWarning("Database error.", e, LocalDateTime.now());
} }
} }
} }

View file

@ -22,49 +22,49 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
public class LoggingService { public class LoggingService {
private Logger logger; private static final Logger logger;
private DateTimeFormatter dateFormat; private static final DateTimeFormatter dateFormat;
private Log log; private static final Log log;
public LoggingService(Level writerLevel) { static {
this.log = new Log(); log = new Log();
this.logger = new Logger(writerLevel); logger = new Logger(Level.INFO);
this.dateFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); dateFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
} }
public void logSevere(String message, Exception exception, LocalDateTime time) { public static void logSevere(String message, Exception exception, LocalDateTime time) {
setValues(message, exception, time); setValues(message, exception, time);
Services.singleExecutor.execute(severeLogger); Services.singleExecutor.execute(severeLogger);
} }
public void logWarning(String message, Exception exception, LocalDateTime time) { public static void logWarning(String message, Exception exception, LocalDateTime time) {
setValues(message, exception, time); setValues(message, exception, time);
Services.singleExecutor.execute(warningLogger); Services.singleExecutor.execute(warningLogger);
} }
public void logInfo(String message, LocalDateTime time) { public static void logInfo(String message, LocalDateTime time) {
setValues(message, null, time); setValues(message, null, time);
Services.singleExecutor.execute(infoLogger); Services.singleExecutor.execute(infoLogger);
} }
private void setValues(String message, Exception exception, LocalDateTime time) { private static void setValues(String message, Exception exception, LocalDateTime time) {
this.log.message = message; log.message = message;
this.log.exception = exception; log.exception = exception;
this.log.time = dateFormat.format(time); log.time = dateFormat.format(time);
} }
private Runnable severeLogger = () -> { private static Runnable severeLogger = () -> {
this.log.level = Level.SEVERE; log.level = Level.SEVERE;
this.logger.log(this.log); logger.log(log);
}; };
private Runnable warningLogger = () -> { private static Runnable warningLogger = () -> {
this.log.level = Level.WARNING; log.level = Level.WARNING;
this.logger.log(log); logger.log(log);
}; };
private Runnable infoLogger = () -> { private static Runnable infoLogger = () -> {
this.log.level = Level.INFO; log.level = Level.INFO;
this.logger.log(log); logger.log(log);
}; };
} }

View file

@ -19,28 +19,16 @@ package com.rohitawate.everest.misc;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import com.rohitawate.everest.controllers.HomeWindowController; import com.rohitawate.everest.controllers.HomeWindowController;
import com.rohitawate.everest.history.HistoryManager; import com.rohitawate.everest.history.HistoryManager;
import com.rohitawate.everest.logging.Level;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.requestmanager.RequestManagersPool;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
public class Services { public class Services {
public static Thread startServicesThread;
public static HistoryManager historyManager; public static HistoryManager historyManager;
public static LoggingService loggingService;
public static HomeWindowController homeWindowController; public static HomeWindowController homeWindowController;
public static Executor singleExecutor; public static Executor singleExecutor;
public static RequestManagersPool pool;
public static void start() { static {
startServicesThread = new Thread(() -> { historyManager = new HistoryManager();
loggingService = new LoggingService(Level.INFO); singleExecutor = MoreExecutors.directExecutor();
historyManager = new HistoryManager();
singleExecutor = MoreExecutors.directExecutor();
pool = new RequestManagersPool();
});
startServicesThread.start();
} }
} }

View file

@ -17,6 +17,7 @@
package com.rohitawate.everest.misc; package com.rohitawate.everest.misc;
import com.rohitawate.everest.controllers.codearea.EverestCodeArea; import com.rohitawate.everest.controllers.codearea.EverestCodeArea;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.settings.Settings; import com.rohitawate.everest.settings.Settings;
import javafx.scene.Parent; import javafx.scene.Parent;
@ -45,9 +46,9 @@ public class ThemeManager {
parent.getStylesheets().add(1, themePath); parent.getStylesheets().add(1, themePath);
} }
Services.loggingService.logInfo("Theme changed to " + Settings.theme + ".", LocalDateTime.now()); LoggingService.logInfo("Theme changed to " + Settings.theme + ".", LocalDateTime.now());
} else { } else {
Services.loggingService.logInfo(Settings.theme + ": No such theme file found.", LocalDateTime.now()); LoggingService.logInfo(Settings.theme + ": No such theme file found.", LocalDateTime.now());
} }
} }
} }
@ -58,7 +59,7 @@ public class ThemeManager {
parent.getStylesheets().add(themeFile.toURI().toString()); parent.getStylesheets().add(themeFile.toURI().toString());
parentNodes.add(parent); parentNodes.add(parent);
} else { } else {
Services.loggingService.logInfo(Settings.theme + ": No such theme file found.", LocalDateTime.now()); LoggingService.logInfo(Settings.theme + ": No such theme file found.", LocalDateTime.now());
} }
} }
} }
@ -68,7 +69,7 @@ public class ThemeManager {
if (syntaxThemeFile.exists()) { if (syntaxThemeFile.exists()) {
everestCodeArea.getStylesheets().add(syntaxThemeFile.toURI().toString()); everestCodeArea.getStylesheets().add(syntaxThemeFile.toURI().toString());
} else { } else {
Services.loggingService.logInfo(Settings.syntaxTheme + ": No such theme file found.", LocalDateTime.now()); LoggingService.logInfo(Settings.syntaxTheme + ": No such theme file found.", LocalDateTime.now());
} }
} }
} }

View file

@ -33,20 +33,9 @@ import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
public abstract class RequestManager extends Service<EverestResponse> { public abstract class RequestManager extends Service<EverestResponse> {
private final Client client; private static final Client client;
long initialTime;
long finalTime;
EverestRequest request; static {
EverestResponse response;
Builder requestBuilder;
RequestManager() {
this.client = initClient();
}
private Client initClient() {
Client client;
client = ClientBuilder.newBuilder() client = ClientBuilder.newBuilder()
.register(MultiPartFeature.class) .register(MultiPartFeature.class)
.build(); .build();
@ -58,10 +47,15 @@ public abstract class RequestManager extends Service<EverestResponse> {
client.property(ClientProperties.CONNECT_TIMEOUT, Settings.connectionTimeOut); client.property(ClientProperties.CONNECT_TIMEOUT, Settings.connectionTimeOut);
if (Settings.connectionReadTimeOutEnable) if (Settings.connectionReadTimeOutEnable)
client.property(ClientProperties.READ_TIMEOUT, Settings.connectionReadTimeOut); client.property(ClientProperties.READ_TIMEOUT, Settings.connectionReadTimeOut);
return client;
} }
long initialTime;
long finalTime;
EverestRequest request;
EverestResponse response;
Builder requestBuilder;
public void setRequest(EverestRequest request) { public void setRequest(EverestRequest request) {
this.request = request; this.request = request;
this.requestBuilder = client.target(request.getTarget().toString()).request(); this.requestBuilder = client.target(request.getTarget().toString()).request();

View file

@ -31,12 +31,12 @@ import java.util.ArrayList;
* returned to the caller. If all the managers in the pool are running, * returned to the caller. If all the managers in the pool are running,
* a new one is created, added to the pool, and returned. * a new one is created, added to the pool, and returned.
*/ */
public class RequestManagersPool { public class RequestManagersFactory {
private ArrayList<GETRequestManager> getManagers; private static ArrayList<GETRequestManager> getManagers;
private ArrayList<DataDispatchRequestManager> dataManagers; private static ArrayList<DataDispatchRequestManager> dataManagers;
private ArrayList<DELETERequestManager> deleteManagers; private static ArrayList<DELETERequestManager> deleteManagers;
public GETRequestManager get() { public static GETRequestManager get() {
if (getManagers == null) if (getManagers == null)
getManagers = new ArrayList<>(); getManagers = new ArrayList<>();
@ -53,7 +53,7 @@ public class RequestManagersPool {
return newManager; return newManager;
} }
public DataDispatchRequestManager data() { public static DataDispatchRequestManager data() {
if (dataManagers == null) if (dataManagers == null)
dataManagers = new ArrayList<>(); dataManagers = new ArrayList<>();
@ -70,7 +70,7 @@ public class RequestManagersPool {
return newManager; return newManager;
} }
public DELETERequestManager delete() { public static DELETERequestManager delete() {
if (deleteManagers == null) if (deleteManagers == null)
deleteManagers = new ArrayList<>(); deleteManagers = new ArrayList<>();

View file

@ -17,8 +17,8 @@
package com.rohitawate.everest.settings; package com.rohitawate.everest.settings;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.rohitawate.everest.logging.LoggingService;
import com.rohitawate.everest.misc.EverestUtilities; import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.Services;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -60,7 +60,7 @@ public class SettingsLoader implements Runnable {
Settings.syntaxTheme = EverestUtilities.trimString(setStringSetting(Settings.syntaxTheme, "syntaxTheme")); Settings.syntaxTheme = EverestUtilities.trimString(setStringSetting(Settings.syntaxTheme, "syntaxTheme"));
Settings.showHistoryRange = setIntegerSetting(Settings.showHistoryRange, "showHistoryRange"); Settings.showHistoryRange = setIntegerSetting(Settings.showHistoryRange, "showHistoryRange");
} catch (IOException IOE) { } catch (IOException IOE) {
Services.loggingService.logInfo("Settings file not found. Using defaults.", LocalDateTime.now()); LoggingService.logInfo("Settings file not found. Using defaults.", LocalDateTime.now());
} }
} }
@ -69,9 +69,9 @@ public class SettingsLoader implements Runnable {
if (value != null) { if (value != null) {
defaultValue = value.toString(); defaultValue = value.toString();
Services.loggingService.logInfo("[" + identifier + "]: Loaded: " + defaultValue, LocalDateTime.now()); LoggingService.logInfo("[" + identifier + "]: Loaded: " + defaultValue, LocalDateTime.now());
} else { } else {
Services.loggingService.logInfo("[" + identifier + "]: Not found. Using default value.", LocalDateTime.now()); LoggingService.logInfo("[" + identifier + "]: Not found. Using default value.", LocalDateTime.now());
} }
return defaultValue; return defaultValue;
@ -82,9 +82,9 @@ public class SettingsLoader implements Runnable {
if (value != null) { if (value != null) {
defaultValue = value.asInt(); defaultValue = value.asInt();
Services.loggingService.logInfo("[" + identifier + "]: Loaded: " + defaultValue, LocalDateTime.now()); LoggingService.logInfo("[" + identifier + "]: Loaded: " + defaultValue, LocalDateTime.now());
} else { } else {
Services.loggingService.logInfo("[" + identifier + "]: Not found. Using default value.", LocalDateTime.now()); LoggingService.logInfo("[" + identifier + "]: Not found. Using default value.", LocalDateTime.now());
} }
return defaultValue; return defaultValue;
@ -95,9 +95,9 @@ public class SettingsLoader implements Runnable {
if (value != null) { if (value != null) {
defaultValue = value.asBoolean(); defaultValue = value.asBoolean();
Services.loggingService.logInfo("[" + identifier + "]: Loaded: " + defaultValue, LocalDateTime.now()); LoggingService.logInfo("[" + identifier + "]: Loaded: " + defaultValue, LocalDateTime.now());
} else { } else {
Services.loggingService.logInfo("[" + identifier + "]: Not found. Using default value.", LocalDateTime.now()); LoggingService.logInfo("[" + identifier + "]: Not found. Using default value.", LocalDateTime.now());
} }
return defaultValue; return defaultValue;

View file

@ -322,13 +322,13 @@
} }
.visualizerRootLabel { .visualizerRootLabel {
-fx-font-size: 17px; -fx-font-size: 16px;
-fx-text-fill: #dedede; -fx-text-fill: #dedede;
-fx-font-weight: bold; -fx-font-weight: bold;
} }
.visualizerKeyLabel { .visualizerKeyLabel {
-fx-font-size: 17px; -fx-font-size: 16px;
-fx-text-fill: #bababa; -fx-text-fill: #bababa;
-fx-font-weight: bold; -fx-font-weight: bold;
} }
@ -363,7 +363,7 @@
.tree-cell:selected, .tree-cell:selected,
.tree-cell:focused { .tree-cell:focused {
-fx-background-color: cornflowerblue; -fx-background-color: darkred;
} }
.tree-cell:selected .label { .tree-cell:selected .label {