Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for UI freezes #43

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
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
564 changes: 358 additions & 206 deletions src/main/java/org/ton/actions/MyLocalTon.java

Large diffs are not rendered by default.

206 changes: 122 additions & 84 deletions src/main/java/org/ton/db/DbPool.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package org.ton.executors.blockchainexplorer;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@Slf4j
public class BlockchainExplorerExecutor {

Expand All @@ -31,14 +29,12 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
try {
log.info("execute: {}", String.join(" ", withBinaryCommand));

ExecutorService executorService = Executors.newSingleThreadExecutor();

final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand).redirectErrorStream(true);

pb.directory(new File(new File(binaryPath).getParent()));
Process p = pb.start();
p.waitFor(5, TimeUnit.SECONDS);
Future<String> future = executorService.submit(() -> {
Future<String> future = ForkJoinPool.commonPool().submit(() -> {
try {
Thread.currentThread().setName("blockchain-explorer-" + node.getNodeName());

Expand All @@ -56,8 +52,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
}
});

executorService.shutdown();

return Pair.of(p, future);

} catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package org.ton.executors.createhardfork;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@Slf4j
public class HardforkExecutor {

Expand All @@ -31,14 +29,12 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
try {
log.debug("execute: {}", String.join(" ", withBinaryCommand));

ExecutorService executorService = Executors.newSingleThreadExecutor();

final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand).redirectErrorStream(true);

pb.directory(new File(new File(binaryPath).getParent()));
Process p = pb.start();
p.waitFor(5, TimeUnit.SECONDS);
Future<String> future = executorService.submit(() -> {
Future<String> future = ForkJoinPool.commonPool().submit(() -> {
try {
Thread.currentThread().setName("create-hardfork-" + node.getNodeName());

Expand All @@ -56,8 +52,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
}
});

executorService.shutdown();

return Pair.of(p, future);

} catch (final IOException e) {
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/org/ton/executors/dhtserver/DhtServerExecutor.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package org.ton.executors.dhtserver;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

@Slf4j
public class DhtServerExecutor {

Expand All @@ -31,14 +29,12 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
try {
log.debug("execute: {}", String.join(" ", withBinaryCommand));

ExecutorService executorService = Executors.newSingleThreadExecutor();

final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand).redirectErrorStream(true);

pb.directory(new File(new File(binaryPath).getParent()));
Process p = pb.start();
p.waitFor(5, TimeUnit.SECONDS);
Future<String> future = executorService.submit(() -> {
Future<String> future = ForkJoinPool.commonPool().submit(() -> {
try {
Thread.currentThread().setName("DHT server on " + node.getNodeName());

Expand All @@ -56,8 +52,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
}
});

executorService.shutdown();

return Pair.of(p, future);

} catch (final IOException e) {
Expand Down
22 changes: 8 additions & 14 deletions src/main/java/org/ton/executors/fift/FiftExecutor.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package org.ton.executors.fift;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;

@Slf4j
public class FiftExecutor {
Expand All @@ -32,8 +30,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
try {
log.debug("execute: {}", String.join(" ", withBinaryCommand));

ExecutorService executorService = Executors.newSingleThreadExecutor();

final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand).redirectErrorStream(true);
Map<String, String> env = pb.environment();
env.put("FIFTPATH", node.getTonBinDir() + "lib");
Expand All @@ -42,7 +38,7 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
Process p = pb.start();
p.waitFor(5, TimeUnit.SECONDS);

Future<String> future = executorService.submit(() -> {
Future<String> future = ForkJoinPool.commonPool().submit(() -> {
try {
Thread.currentThread().setName("fift-" + node.getNodeName());

Expand All @@ -60,8 +56,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
}
});

executorService.shutdown();

return Pair.of(p, future);

} catch (final IOException e) {
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/org/ton/executors/liteclient/LiteClientExecutor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package org.ton.executors.liteclient;

import static java.util.Objects.isNull;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
Expand All @@ -9,16 +17,6 @@
import org.ton.main.Main;
import org.ton.settings.Node;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import static java.util.Objects.isNull;

@Slf4j
public class LiteClientExecutor {

Expand Down Expand Up @@ -66,14 +64,12 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
if (Main.appActive.get()) {
log.debug("execute: {}", String.join(" ", withBinaryCommand));

ExecutorService executorService = Executors.newSingleThreadExecutor();

final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand).redirectErrorStream(true);

pb.directory(new File(new File(binaryPath).getParent()));
Process p = pb.start();
p.waitFor(5, TimeUnit.SECONDS);
Future<String> future = executorService.submit(() -> {
Future<String> future = ForkJoinPool.commonPool().submit(() -> {
try {
Thread.currentThread().setName("lite-client-" + node.getNodeName());

Expand All @@ -90,8 +86,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
}
});

executorService.shutdown();

return Pair.of(p, future);
}
return null;
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/org/ton/executors/tonhttpapi/TonHttpApiExecutor.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.ton.executors.tonhttpapi;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;
import static org.ton.main.App.mainController;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import static org.ton.main.App.mainController;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.settings.Node;

@Slf4j
public class TonHttpApiExecutor {
Expand Down Expand Up @@ -48,13 +46,11 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {

log.info("execute: {}", String.join(" ", withBinaryCommand));

ExecutorService executorService = Executors.newSingleThreadExecutor();

final ProcessBuilder pb = new ProcessBuilder(withBinaryCommand);

Process p = pb.start();
p.waitFor(5, TimeUnit.SECONDS);
Future<String> future = executorService.submit(() -> {
Future<String> future = ForkJoinPool.commonPool().submit(() -> {
try {
Thread.currentThread().setName("ton-http-api-" + node.getNodeName());

Expand All @@ -73,8 +69,6 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
}
});

executorService.shutdown();

return Pair.of(p, future);

} catch (final IOException e) {
Expand Down
Loading