Use GlobalThreadPool in conjunction with CompletableFuture
This commit is contained in:
parent
3c1e0eea96
commit
4f7060dfef
|
@ -6,6 +6,7 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.time.Instant;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.recorder.Recorder;
|
||||
import ctbrec.ui.controls.Dialogs;
|
||||
|
@ -36,6 +37,6 @@ public class RemoveTimeLimitAction {
|
|||
Dialogs.showError(source.getScene(), "Error", "Couln't remove stop date", e);
|
||||
return false;
|
||||
}
|
||||
}).whenComplete((r,e) -> source.setCursor(Cursor.DEFAULT));
|
||||
}, GlobalThreadPool.get()).whenComplete((r,e) -> source.setCursor(Cursor.DEFAULT));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.concurrent.CompletableFuture;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.SubsequentAction;
|
||||
import ctbrec.recorder.Recorder;
|
||||
|
@ -82,7 +83,7 @@ public class SetStopDateAction {
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}).whenComplete((r, e) -> {
|
||||
}, GlobalThreadPool.get()).whenComplete((r, e) -> {
|
||||
source.setCursor(Cursor.DEFAULT);
|
||||
if (e != null) {
|
||||
LOG.error("Error", e);
|
||||
|
|
|
@ -9,13 +9,13 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Hmac;
|
||||
import ctbrec.Settings;
|
||||
import ctbrec.Settings.DirectoryStructure;
|
||||
|
@ -436,7 +436,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
|
||||
public void saveConfig() {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
try {
|
||||
Config.getInstance().save();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.recorder.Recorder;
|
||||
import ctbrec.sites.camsoda.Camsoda;
|
||||
|
@ -136,7 +137,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
|
|||
});
|
||||
}
|
||||
};
|
||||
new Thread(task).start();
|
||||
GlobalThreadPool.submit(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -180,17 +181,17 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
|
|||
grid.add(createLabel(formatter.format(endTime), false), 1, 1);
|
||||
Button record = new Button("Record Model");
|
||||
record.setTooltip(new Tooltip(record.getText()));
|
||||
record.setOnAction((evt) -> record(model));
|
||||
record.setOnAction(evt -> record(model));
|
||||
grid.add(record, 1, 2);
|
||||
GridPane.setMargin(record, new Insets(10));
|
||||
Button follow = new Button("Follow");
|
||||
follow.setTooltip(new Tooltip(follow.getText()));
|
||||
follow.setOnAction((evt) -> follow(model));
|
||||
follow.setOnAction(evt -> follow(model));
|
||||
grid.add(follow, 1, 3);
|
||||
GridPane.setMargin(follow, new Insets(10));
|
||||
Button openInBrowser = new Button("Open in Browser");
|
||||
openInBrowser.setTooltip(new Tooltip(openInBrowser.getText()));
|
||||
openInBrowser.setOnAction((evt) -> DesktopIntegration.open(model.getUrl()));
|
||||
openInBrowser.setOnAction(evt -> DesktopIntegration.open(model.getUrl()));
|
||||
grid.add(openInBrowser, 1, 4);
|
||||
GridPane.setMargin(openInBrowser, new Insets(10));
|
||||
root.setCenter(grid);
|
||||
|
@ -202,7 +203,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
|
|||
|
||||
private void follow(Model model) {
|
||||
setCursor(Cursor.WAIT);
|
||||
new Thread(() -> {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
try {
|
||||
SiteUiFactory.getUi(model.getSite()).login();
|
||||
model.follow();
|
||||
|
@ -210,30 +211,26 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
|
|||
LOG.error("Couldn't follow model {}", model, e);
|
||||
showErrorDialog("Oh no!", "Couldn't follow model", e.getMessage());
|
||||
} finally {
|
||||
Platform.runLater(() -> {
|
||||
setCursor(Cursor.DEFAULT);
|
||||
});
|
||||
Platform.runLater(() -> setCursor(Cursor.DEFAULT));
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
private void record(Model model) {
|
||||
setCursor(Cursor.WAIT);
|
||||
new Thread(() -> {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
try {
|
||||
recorder.addModel(model);
|
||||
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) {
|
||||
showErrorDialog("Oh no!", "Couldn't add model to the recorder", "Recorder error: " + e.getMessage());
|
||||
} finally {
|
||||
Platform.runLater(() -> {
|
||||
setCursor(Cursor.DEFAULT);
|
||||
});
|
||||
Platform.runLater(() -> setCursor(Cursor.DEFAULT));
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
private void loadImage(Model model, ImageView thumb) {
|
||||
new Thread(() -> {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
try {
|
||||
String url = camsoda.getBaseUrl() + "/api/v1/user/" + model.getName();
|
||||
Request detailRequest = new Request.Builder().url(url).build();
|
||||
|
@ -270,7 +267,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
|
|||
} catch (Exception e) {
|
||||
LOG.error("Couldn't load model details", e);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
private Node createLabel(String string, boolean bold) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.Model.State;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -285,7 +286,7 @@ public class ThumbCell extends StackPane {
|
|||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}).whenComplete((result, exception) -> {
|
||||
}, GlobalThreadPool.get()).whenComplete((result, exception) -> {
|
||||
startPreview = null;
|
||||
if (result.booleanValue()) {
|
||||
setPreviewVisible(previewTrigger, true);
|
||||
|
@ -587,7 +588,7 @@ public class ThumbCell extends StackPane {
|
|||
} finally {
|
||||
Platform.runLater(() -> setCursor(Cursor.DEFAULT));
|
||||
}
|
||||
});
|
||||
}, GlobalThreadPool.get());
|
||||
}
|
||||
|
||||
void recordLater(boolean recordLater) {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package ctbrec.ui.tabs;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.ui.CamrecApplication;
|
||||
import ctbrec.ui.CamrecApplication.Release;
|
||||
|
@ -47,7 +46,7 @@ public class UpdateTab extends Tab implements TabSelectionListener {
|
|||
}
|
||||
|
||||
public void loadChangeLog() {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
Request req = new Request.Builder().url("https://pastebin.com/raw/fiAPtM0s").build();
|
||||
try (Response resp = CamrecApplication.httpClient.execute(req)) {
|
||||
if (resp.isSuccessful()) {
|
||||
|
|
Loading…
Reference in New Issue