Project-wide cleanup and optimizations

This commit is contained in:
Rohit Awate 2018-07-04 19:23:31 +05:30
parent ca6bcabdb9
commit f1ca82d61c
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
15 changed files with 579 additions and 617 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ dependency-reduced-pom.xml
BugReporter/src/META-INF/
Everest/
out/
BugReporter.jar

View file

@ -15,7 +15,6 @@
*/
package com.rohitawate.everest;
import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.misc.ThemeManager;
import com.rohitawate.everest.settings.SettingsLoader;
@ -51,8 +50,6 @@ public class Main extends Application {
dashboardStage.setScene(new Scene(homeWindow));
dashboardStage.setTitle("Everest");
dashboardStage.show();
EverestUtilities.createBugReporter();
}
public static void main(String args[]) {

View file

@ -1,186 +0,0 @@
package com.rohitawate.everest.controllers;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutionException;
import com.jfoenix.controls.JFXButton;
import com.rohitawate.everest.misc.Services;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
public abstract class AbstractSearchablePaneController<T> implements Initializable {
@FXML
private StackPane searchPromptLayer, searchLayer, searchFailedLayer;
@FXML
private JFXButton clearSearchFieldButton;
@FXML
private TextField searchTextField;
@FXML
private VBox searchTab, searchBox, searchPane;
private List<Searchable<T>> searchableItems;
protected static class SearchEntry<T> {
private final Parent fxmlItem;
private final Searchable<T> searchable;
public SearchEntry(Parent fxmlItem, Searchable<T> searchable) {
super();
this.fxmlItem = fxmlItem;
this.searchable = searchable;
}
public Parent getFxmlItem() {
return fxmlItem;
}
public Searchable<T> getSearchable() {
return searchable;
}
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
searchableItems = new ArrayList<>();
searchLayer.visibleProperty().bind(searchTextField.textProperty().isNotEmpty());
searchTextField.textProperty().addListener(((observable, oldValue, newValue) -> {
searchBox.getChildren().remove(0, searchBox.getChildren().size());
searchFailedLayer.setVisible(false);
List<Searchable<T>> searchResults = getSearchResults(searchTextField.getText());
//TODO: this is calculating relativityIndex again
searchResults.sort((controller1, controller2) -> {
int relativity1 = controller1.getRelativityIndex(searchTextField.getText());
int relativity2 = controller2.getRelativityIndex(searchTextField.getText());
return relativity2 - relativity1;
});
if (searchResults.size() != 0) {
for (Searchable<T> controller : searchResults) {
addSearchItem(controller.getState());
}
} else {
searchFailedLayer.setVisible(true);
}
}));
clearSearchFieldButton.setOnAction(e -> searchTextField.clear());
Platform.runLater(this::loadInitialItemsAsync);
}
private void loadInitialItemsAsync() {
Task<List<T>> entryLoader = new Task<List<T>>() {
@Override
protected List<T> call() {
return loadInitialEntries();
}
};
entryLoader.setOnSucceeded(e -> {
try {
List<T> entries = entryLoader.get();
if (entries.size() == 0) {
searchPromptLayer.setVisible(true);
return;
}
for (T state : entries)
addHistoryItem(state);
} catch (InterruptedException | ExecutionException E) {
Services.loggingService.logSevere("Task thread interrupted while populating HistoryTab.", E,
LocalDateTime.now());
}
});
entryLoader.setOnFailed(e -> Services.loggingService.logWarning("Failed to load history.",
(Exception) entryLoader.getException(), LocalDateTime.now()));
new Thread(entryLoader).start();
}
private void addSearchItem(T state) {
appendToList(state, searchBox, false);
}
protected abstract List<T> loadInitialEntries();
public void focusSearchField() {
searchTextField.requestFocus();
}
private Searchable<T> appendToList(T state, VBox layer, boolean appendToStart) {
searchPromptLayer.setVisible(false);
try {
SearchEntry<T> searchEntry = createEntryFromState(state);
if (appendToStart)
layer.getChildren().add(0, searchEntry.getFxmlItem());
else
layer.getChildren().add(searchEntry.getFxmlItem());
return searchEntry.getSearchable();
} catch (IOException e) {
Services.loggingService.logSevere("Could not append HistoryItem to list.", e, LocalDateTime.now());
}
return null;
}
protected abstract SearchEntry<T> createEntryFromState(T state) throws IOException;
public void addHistoryItem(T state) {
Searchable<T> controller = appendToList(state, searchTab, true);
searchableItems.add(controller);
}
private List<Searchable<T>> getSearchResults(String searchString) {
List<Searchable<T>> filteredList = new ArrayList<>();
for (Searchable<T> controller : searchableItems) {
int relativityIndex = controller.getRelativityIndex(searchString);
// Split the string into words and get total relativity index as sum of
// individual indices.
String words[] = searchString.split("\\s");
for (String word : words)
relativityIndex += controller.getRelativityIndex(word);
if (relativityIndex != 0)
filteredList.add(controller);
}
return filteredList;
}
public void toggleVisibilityIn(SplitPane splitPane) {
if (searchPane.isVisible()) {
searchPane = (VBox) splitPane.getItems().remove(0);
} else {
splitPane.getItems().add(0, searchPane);
}
searchPane.setVisible(!searchPane.isVisible());
}
}

View file

@ -23,6 +23,7 @@ import java.util.ResourceBundle;
import javax.ws.rs.core.MediaType;
import com.rohitawate.everest.controllers.search.Searchable;
import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.misc.Services;

View file

@ -1,19 +1,34 @@
/*
* Copyright 2018 Rohit Awate.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rohitawate.everest.controllers;
import com.rohitawate.everest.controllers.search.SearchablePaneController;
import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.misc.Services;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.input.MouseButton;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.misc.Services;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.VBox;
public class SearchPaneController extends AbstractSearchablePaneController<DashboardState> {
public class HistoryPaneController extends SearchablePaneController<DashboardState> {
private List<Consumer<DashboardState>> stateClickHandler = new LinkedList<>();
@ -27,8 +42,6 @@ public class SearchPaneController extends AbstractSearchablePaneController<Dashb
Parent historyItem = loader.load();
HistoryItemController controller = loader.getController();
controller = loader.getController();
controller.setState(state);
// Clicking on HistoryItem opens it up in a new tab
@ -36,7 +49,8 @@ public class SearchPaneController extends AbstractSearchablePaneController<Dashb
if (mouseEvent.getButton() == MouseButton.PRIMARY)
handleClick(state);
});
return new SearchEntry<DashboardState>(historyItem, controller);
return new SearchEntry<>(historyItem, controller);
}
private void handleClick(DashboardState state) {
@ -48,6 +62,4 @@ public class SearchPaneController extends AbstractSearchablePaneController<Dashb
public void addItemClickHandler(Consumer<DashboardState> handler) {
stateClickHandler.add(handler);
}
}

View file

@ -16,24 +16,12 @@
package com.rohitawate.everest.controllers;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ResourceBundle;
import com.fasterxml.jackson.core.type.TypeReference;
import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.KeyMap;
import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.misc.ThemeManager;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.StringProperty;
@ -45,11 +33,18 @@ import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.ResourceBundle;
public class HomeWindowController implements Initializable {
@FXML
private StackPane homeWindowSP;
@ -57,9 +52,8 @@ public class HomeWindowController implements Initializable {
private SplitPane splitPane;
@FXML
private TabPane homeWindowTabPane;
@FXML
private SearchPaneController searchPaneController;
private HistoryPaneController historyPaneController;
private HashMap<Tab, DashboardController> tabControllerMap;
@ -69,7 +63,7 @@ public class HomeWindowController implements Initializable {
tabControllerMap = new LinkedHashMap<>();
recoverState();
searchPaneController.addItemClickHandler(this::addTab);
historyPaneController.addItemClickHandler(this::addTab);
homeWindowSP.setFocusTraversable(true);
Platform.runLater(() -> {
@ -79,9 +73,6 @@ public class HomeWindowController implements Initializable {
// Saves the state of the application before closing
Stage thisStage = (Stage) homeWindowSP.getScene().getWindow();
thisStage.setOnCloseRequest(e -> saveState());
});
}
@ -109,7 +100,7 @@ public class HomeWindowController implements Initializable {
homeWindowTabPane.getTabs().remove(activeTab);
tabControllerMap.remove(activeTab);
} else if (KeyMap.searchHistory.match(e)) {
searchPaneController.focusSearchField();
historyPaneController.focusSearchField();
} else if (KeyMap.focusParams.match(e)) {
Tab activeTab = getActiveTab();
DashboardController controller = tabControllerMap.get(activeTab);
@ -140,7 +131,7 @@ public class HomeWindowController implements Initializable {
}
private void toggleHistoryPane() {
searchPaneController.toggleVisibilityIn(splitPane);
historyPaneController.toggleVisibilityIn(splitPane);
}
private void addTab() {
@ -224,12 +215,9 @@ public class HomeWindowController implements Initializable {
} finally {
Services.loggingService.logInfo("Application loaded.", LocalDateTime.now());
}
}
public void addHistoryItem(DashboardState state) {
searchPaneController.addHistoryItem(state);
historyPaneController.addHistoryItem(state);
}
}

View file

@ -1,15 +0,0 @@
package com.rohitawate.everest.controllers;
/**
* a searchable item that is used in a search-pane.
* @author pmucha
*
* @param <T>
*/
public interface Searchable<T> {
int getRelativityIndex(String searchString);
T getState();
}

View file

@ -0,0 +1,28 @@
/*
* Copyright 2018 Rohit Awate.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rohitawate.everest.controllers.search;
/**
* A searchable item that is used in a SearchPane.
*
* @param <T> The search item that Searchable encapsulates.
* @author pmucha
*/
public interface Searchable<T> {
int getRelativityIndex(String searchString);
T getState();
}

View file

@ -0,0 +1,194 @@
/*
* Copyright 2018 Rohit Awate.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rohitawate.everest.controllers.search;
import com.jfoenix.controls.JFXButton;
import com.rohitawate.everest.misc.Services;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutionException;
public abstract class SearchablePaneController<T> implements Initializable {
@FXML
private StackPane searchPromptLayer, searchLayer, searchFailedLayer;
@FXML
private JFXButton clearSearchFieldButton;
@FXML
private TextField searchTextField;
@FXML
private VBox searchTab, searchBox, searchPane;
private List<Searchable<T>> searchableItems;
protected static class SearchEntry<T> {
private final Parent fxmlItem;
private final Searchable<T> searchable;
public SearchEntry(Parent fxmlItem, Searchable<T> searchable) {
super();
this.fxmlItem = fxmlItem;
this.searchable = searchable;
}
public Parent getFxmlItem() {
return fxmlItem;
}
public Searchable<T> getSearchable() {
return searchable;
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
searchableItems = new ArrayList<>();
searchLayer.visibleProperty().bind(searchTextField.textProperty().isNotEmpty());
searchTextField.textProperty().addListener(((observable, oldValue, newValue) -> {
searchBox.getChildren().remove(0, searchBox.getChildren().size());
searchFailedLayer.setVisible(false);
List<Searchable<T>> searchResults = getSearchResults(searchTextField.getText());
searchResults.sort((controller1, controller2) -> {
int relativity1 = controller1.getRelativityIndex(searchTextField.getText());
int relativity2 = controller2.getRelativityIndex(searchTextField.getText());
return relativity2 - relativity1;
});
if (searchResults.size() != 0) {
for (Searchable<T> controller : searchResults) {
addSearchItem(controller.getState());
}
} else {
searchFailedLayer.setVisible(true);
}
}));
clearSearchFieldButton.setOnAction(e -> searchTextField.clear());
Platform.runLater(this::loadInitialItemsAsync);
}
private void loadInitialItemsAsync() {
Task<List<T>> entryLoader = new Task<List<T>>() {
@Override
protected List<T> call() {
return loadInitialEntries();
}
};
entryLoader.setOnSucceeded(e -> {
try {
List<T> entries = entryLoader.get();
if (entries.size() == 0) {
searchPromptLayer.setVisible(true);
return;
}
for (T state : entries)
addHistoryItem(state);
} catch (InterruptedException | ExecutionException E) {
Services.loggingService.logSevere("Task thread interrupted while populating HistoryTab.", E,
LocalDateTime.now());
}
});
entryLoader.setOnFailed(e -> Services.loggingService.logWarning("Failed to load history.",
(Exception) entryLoader.getException(), LocalDateTime.now()));
Services.singleExecutor.execute(entryLoader);
}
private void addSearchItem(T state) {
appendToList(state, searchBox, false);
}
protected abstract List<T> loadInitialEntries();
public void focusSearchField() {
searchTextField.requestFocus();
}
private Searchable<T> appendToList(T state, VBox layer, boolean appendToStart) {
searchPromptLayer.setVisible(false);
try {
SearchEntry<T> searchEntry = createEntryFromState(state);
if (appendToStart)
layer.getChildren().add(0, searchEntry.getFxmlItem());
else
layer.getChildren().add(searchEntry.getFxmlItem());
return searchEntry.getSearchable();
} catch (IOException e) {
Services.loggingService.logSevere("Could not append HistoryItem to list.", e, LocalDateTime.now());
}
return null;
}
protected abstract SearchEntry<T> createEntryFromState(T state) throws IOException;
public void addHistoryItem(T state) {
Searchable<T> controller = appendToList(state, searchTab, true);
searchableItems.add(controller);
}
private List<Searchable<T>> getSearchResults(String searchString) {
List<Searchable<T>> filteredList = new ArrayList<>();
for (Searchable<T> controller : searchableItems) {
int relativityIndex = controller.getRelativityIndex(searchString);
// Split the string into words and get total relativity index as sum of
// individual indices.
String words[] = searchString.split("\\s");
for (String word : words)
relativityIndex += controller.getRelativityIndex(word);
if (relativityIndex != 0)
filteredList.add(controller);
}
return filteredList;
}
public void toggleVisibilityIn(SplitPane splitPane) {
if (searchPane.isVisible()) {
searchPane = (VBox) splitPane.getItems().remove(0);
} else {
splitPane.getItems().add(0, searchPane);
}
searchPane.setVisible(!searchPane.isVisible());
}
}

View file

@ -16,21 +16,6 @@
package com.rohitawate.everest.history;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rohitawate.everest.controllers.state.DashboardState;
@ -39,6 +24,16 @@ import com.rohitawate.everest.misc.EverestUtilities;
import com.rohitawate.everest.misc.Services;
import com.rohitawate.everest.settings.Settings;
import javax.ws.rs.core.MediaType;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
public class HistoryManager {
private Connection conn;
private JsonNode queries;
@ -387,19 +382,8 @@ public class HistoryManager {
}
}
if (state.params.size() > 0) {
// Saves request parameters
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
for (FieldState fieldState : state.params) {
statement.setInt(1, requestID);
statement.setString(2, "Param");
statement.setString(3, fieldState.key);
statement.setString(4, fieldState.value);
statement.setInt(5, fieldState.checked ? 1 : 0);
statement.executeUpdate();
}
}
saveTuple(state.params, "Param", requestID);
if (!(state.httpMethod.equals("GET") || state.httpMethod.equals("DELETE"))) {
// Maps the request to its ContentType for faster retrieval
@ -423,48 +407,11 @@ public class HistoryManager {
statement.executeUpdate();
break;
case MediaType.APPLICATION_FORM_URLENCODED:
if (state.urlStringTuples.size() > 0) {
for (FieldState fieldState : state.urlStringTuples) {
// Saves the string tuples
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
statement.setInt(1, requestID);
statement.setString(2, "String");
statement.setString(3, fieldState.key);
statement.setString(4, fieldState.value);
statement.setInt(5, fieldState.checked ? 1 : 0);
statement.executeUpdate();
}
}
saveTuple(state.urlStringTuples, "String", requestID);
break;
case MediaType.MULTIPART_FORM_DATA:
if (state.formStringTuples.size() > 0) {
for (FieldState fieldState : state.formStringTuples) {
// Saves the string tuples
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
statement.setInt(1, requestID);
statement.setString(2, "String");
statement.setString(3, fieldState.key);
statement.setString(4, fieldState.value);
statement.setInt(5, fieldState.checked ? 1 : 0);
statement.executeUpdate();
}
}
if (state.formFileTuples.size() > 0) {
for (FieldState fieldState : state.formFileTuples) {
// Saves the string tuples
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
statement.setInt(1, requestID);
statement.setString(2, "File");
statement.setString(3, fieldState.key);
statement.setString(4, fieldState.value);
statement.setInt(5, fieldState.checked ? 1 : 0);
statement.executeUpdate();
}
}
saveTuple(state.formStringTuples, "String", requestID);
saveTuple(state.formFileTuples, "File", requestID);
break;
}
}
@ -472,5 +419,25 @@ public class HistoryManager {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now());
}
}
private void saveTuple(ArrayList<FieldState> tuples, String tupleType, int requestID) {
if (tuples.size() > 0) {
for (FieldState fieldState : tuples) {
// Saves the string tuples
try {
statement = conn.prepareStatement(EverestUtilities.trimString(queries.get("saveTuple").toString()));
statement.setInt(1, requestID);
statement.setString(2, tupleType);
statement.setString(3, fieldState.key);
statement.setString(4, fieldState.value);
statement.setInt(5, fieldState.checked ? 1 : 0);
statement.executeUpdate();
} catch (SQLException e) {
Services.loggingService.logWarning("Database error.", e, LocalDateTime.now());
}
}
}
}
}
}

View file

@ -19,14 +19,6 @@ package com.rohitawate.everest.misc;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
public class EverestUtilities {
public static ObjectMapper jsonMapper;
@ -44,21 +36,4 @@ public class EverestUtilities {
public static String trimString(String input) {
return input.replaceAll("\"", "");
}
/**
* Copies the BugReporter from within the JAR to the installation directory.
*/
public static void createBugReporter() {
new Thread(() -> {
InputStream inputStream = EverestUtilities.class.getResourceAsStream("/BugReporter.jar");
Path bugReporter = Paths.get("Everest/BugReporter.jar");
try {
Files.copy(inputStream, bugReporter, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
Services.loggingService.logInfo("BugReporter was copied to installation directory.", LocalDateTime.now());
}).start();
}
}

View file

@ -16,74 +16,70 @@
package com.rohitawate.everest.requestmanager;
import java.util.LinkedList;
import java.util.ArrayList;
/**
* Provides the various RequestManagers employed by Everest.
* <p>
* Pools are created as needed i.e. the first DELETE request
* will create the pool of DELETERequestManagers. If a DELETE
* request is never made, the pool won't be created. Same applies
* for all other types of requests.
* <p>
* When demanding a RequestManager, the pool is checked linearly.
* The first RequestManager which is not currently running will be
* returned to the caller. If all the managers in the pool are running,
* a new one is created, added to the pool, and returned.
*/
public class RequestManagersPool {
private LinkedList<GETRequestManager> getManagers;
private LinkedList<DataDispatchRequestManager> dataManagers;
private LinkedList<DELETERequestManager> deleteManagers;
private ArrayList<GETRequestManager> getManagers;
private ArrayList<DataDispatchRequestManager> dataManagers;
private ArrayList<DELETERequestManager> deleteManagers;
public GETRequestManager get() {
if (getManagers == null) {
GETRequestManager newManager = new GETRequestManager();
if (getManagers == null)
getManagers = new ArrayList<>();
new Thread(() -> {
getManagers = new LinkedList<>();
getManagers.add(newManager);
}).start();
return newManager;
} else {
for (GETRequestManager getManager : getManagers) {
if (!getManager.isRunning())
if (!getManager.isRunning()) {
getManager.reset();
return getManager;
}
}
GETRequestManager newManager = new GETRequestManager();
getManagers.add(newManager);
return newManager;
}
}
public DataDispatchRequestManager data() {
if (dataManagers == null) {
DataDispatchRequestManager newManager = new DataDispatchRequestManager();
if (dataManagers == null)
dataManagers = new ArrayList<>();
new Thread(() -> {
dataManagers = new LinkedList<>();
dataManagers.add(newManager);
}).start();
return newManager;
} else {
for (DataDispatchRequestManager dataManager : dataManagers) {
if (!dataManager.isRunning())
if (!dataManager.isRunning()) {
dataManager.reset();
return dataManager;
}
}
DataDispatchRequestManager newManager = new DataDispatchRequestManager();
dataManagers.add(newManager);
return newManager;
}
}
public DELETERequestManager delete() {
if (deleteManagers == null) {
DELETERequestManager newManager = new DELETERequestManager();
if (deleteManagers == null)
deleteManagers = new ArrayList<>();
new Thread(() -> {
deleteManagers = new LinkedList<>();
deleteManagers.add(newManager);
}).start();
return newManager;
} else {
for (DELETERequestManager deleteManager : deleteManagers) {
if (!deleteManager.isRunning())
if (!deleteManager.isRunning()) {
deleteManager.reset();
return deleteManager;
}
}
DELETERequestManager newManager = new DELETERequestManager();
deleteManagers.add(newManager);
@ -91,4 +87,3 @@ public class RequestManagersPool {
return newManager;
}
}
}

Binary file not shown.

View file

@ -25,7 +25,7 @@
<VBox fx:id="searchPane" xmlns="http://javafx.com/javafx/8.0.141"
xmlns:fx="http://javafx.com/fxml/1" alignment="TOP_CENTER" maxWidth="450.0"
minWidth="400.0" SplitPane.resizableWithParent="false" fx:controller="com.rohitawate.everest.controllers.SearchPaneController">
minWidth="400.0" SplitPane.resizableWithParent="false" fx:controller="com.rohitawate.everest.controllers.HistoryPaneController">
<children>
<HBox fx:id="historySearchFieldBox" alignment="CENTER"
fillHeight="false">

View file

@ -1,20 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright 2018 Rohit Awate. ~ ~ Licensed under the Apache License,
Version 2.0 (the "License"); ~ you may not use this file except in compliance
with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~ Unless required by applicable law or agreed to in writing, software ~
distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the
License for the specific language governing permissions and ~ limitations
under the License. -->
<!--
~ Copyright 2018 Rohit Awate.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.StackPane?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<StackPane fx:id="homeWindowSP"
stylesheets="@../../css/Adreana.css"
xmlns="http://javafx.com/javafx/8.0.141"
@ -23,7 +28,7 @@
<children>
<SplitPane fx:id="splitPane" dividerPositions="0.3">
<items>
<fx:include fx:id="searchPane" source="SearchPane.fxml" />
<fx:include fx:id="historyPane" source="HistoryPane.fxml" />
<TabPane fx:id="homeWindowTabPane"
tabClosingPolicy="ALL_TABS" tabMaxHeight="30.0" tabMaxWidth="200.0"
tabMinHeight="30.0" tabMinWidth="200.0"