mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 22:45:21 +01:00
Improve handling of UncaughtExceptionHandler
This commit is contained in:
parent
7ea3676c55
commit
9232a5765b
7 changed files with 32 additions and 28 deletions
|
@ -40,6 +40,7 @@ import bisq.common.handlers.ResultHandler;
|
|||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.setup.CommonSetup;
|
||||
import bisq.common.setup.GracefulShutDownHandler;
|
||||
import bisq.common.setup.UncaughtExceptionHandler;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
|
@ -56,7 +57,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import sun.misc.Signal;
|
||||
|
||||
@Slf4j
|
||||
public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener {
|
||||
public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener, UncaughtExceptionHandler {
|
||||
|
||||
private static final int EXIT_SUCCESS = 0;
|
||||
private static final int EXIT_FAILURE = 1;
|
||||
|
@ -139,6 +140,10 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
|||
|
||||
// Headless versions can call inside launchApplication the onApplicationLaunched() manually
|
||||
protected void onApplicationLaunched() {
|
||||
// As the handler method might be overwritten by subclasses and they use the application as handler
|
||||
// we need to setup the handler after the application is created.
|
||||
CommonSetup.setupUncaughtExceptionHandler(this);
|
||||
|
||||
setupGuice();
|
||||
startApplication();
|
||||
}
|
||||
|
@ -264,6 +269,19 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// UncaughtExceptionHandler implementation
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void handleUncaughtException(Throwable throwable, boolean doShutDown) {
|
||||
log.error(throwable.toString());
|
||||
|
||||
if (doShutDown)
|
||||
gracefulShutDown(() -> log.info("gracefulShutDown complete"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the well-known "user data directory" for the current operating system.
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,6 @@ package bisq.core.app;
|
|||
import bisq.common.UserThread;
|
||||
import bisq.common.app.AppModule;
|
||||
import bisq.common.app.Version;
|
||||
import bisq.common.setup.CommonSetup;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
|
@ -70,7 +69,6 @@ public class BisqHeadlessAppMain extends BisqExecutable {
|
|||
@Override
|
||||
protected void launchApplication() {
|
||||
headlessApp = new BisqHeadlessApp();
|
||||
CommonSetup.setupUncaughtExceptionHandler(BisqHeadlessAppMain.this.headlessApp);
|
||||
|
||||
UserThread.execute(this::onApplicationLaunched);
|
||||
}
|
||||
|
@ -81,6 +79,11 @@ public class BisqHeadlessAppMain extends BisqExecutable {
|
|||
headlessApp.setGracefulShutDownHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUncaughtException(Throwable throwable, boolean doShutDown) {
|
||||
headlessApp.handleUncaughtException(throwable, doShutDown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetupComplete() {
|
||||
log.info("onSetupComplete");
|
||||
|
|
|
@ -33,7 +33,6 @@ import bisq.common.app.DevEnv;
|
|||
import bisq.common.config.Config;
|
||||
import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.setup.GracefulShutDownHandler;
|
||||
import bisq.common.setup.UncaughtExceptionHandler;
|
||||
import bisq.common.util.Profiler;
|
||||
import bisq.common.util.RestartUtil;
|
||||
|
||||
|
@ -55,7 +54,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public abstract class ExecutableForAppWithP2p extends BisqExecutable implements UncaughtExceptionHandler {
|
||||
public abstract class ExecutableForAppWithP2p extends BisqExecutable {
|
||||
private static final long CHECK_MEMORY_PERIOD_SEC = 300;
|
||||
private static final long CHECK_SHUTDOWN_SEC = TimeUnit.HOURS.toSeconds(1);
|
||||
private static final long SHUTDOWN_INTERVAL = TimeUnit.HOURS.toMillis(24);
|
||||
|
@ -177,19 +176,6 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable implements
|
|||
}, TimeUnit.HOURS.toSeconds(2));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// UncaughtExceptionHandler implementation
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void handleUncaughtException(Throwable throwable, boolean doShutDown) {
|
||||
log.error(throwable.toString());
|
||||
|
||||
if (doShutDown)
|
||||
gracefulShutDown(() -> log.info("gracefulShutDown complete"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("InfiniteLoopStatement")
|
||||
protected void keepRunning() {
|
||||
while (true) {
|
||||
|
|
|
@ -24,7 +24,6 @@ import bisq.core.app.CoreModule;
|
|||
import bisq.common.UserThread;
|
||||
import bisq.common.app.AppModule;
|
||||
import bisq.common.handlers.ResultHandler;
|
||||
import bisq.common.setup.CommonSetup;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
|
@ -62,7 +61,6 @@ public class BisqDaemonMain extends BisqHeadlessAppMain implements BisqSetup.Bis
|
|||
@Override
|
||||
protected void launchApplication() {
|
||||
headlessApp = new BisqDaemon();
|
||||
CommonSetup.setupUncaughtExceptionHandler(BisqDaemonMain.this.headlessApp);
|
||||
|
||||
UserThread.execute(this::onApplicationLaunched);
|
||||
}
|
||||
|
@ -73,6 +71,7 @@ public class BisqDaemonMain extends BisqHeadlessAppMain implements BisqSetup.Bis
|
|||
headlessApp.setGracefulShutDownHandler(this);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// We continue with a series of synchronous execution tasks
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,7 +27,6 @@ import bisq.common.UserThread;
|
|||
import bisq.common.app.AppModule;
|
||||
import bisq.common.app.Version;
|
||||
import bisq.common.proto.persistable.PersistedDataHost;
|
||||
import bisq.common.setup.CommonSetup;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -76,9 +75,6 @@ public class BisqAppMain extends BisqExecutable {
|
|||
protected void launchApplication() {
|
||||
BisqApp.setAppLaunchedHandler(application -> {
|
||||
BisqAppMain.this.application = (BisqApp) application;
|
||||
|
||||
// Necessary to do the setup at this point to prevent Bouncy Castle errors
|
||||
CommonSetup.setupUncaughtExceptionHandler(BisqAppMain.this.application);
|
||||
// Map to user thread!
|
||||
UserThread.execute(this::onApplicationLaunched);
|
||||
});
|
||||
|
@ -96,6 +92,12 @@ public class BisqAppMain extends BisqExecutable {
|
|||
application.setGracefulShutDownHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUncaughtException(Throwable throwable, boolean doShutDown) {
|
||||
application.handleUncaughtException(throwable, doShutDown);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// We continue with a series of synchronous execution tasks
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,7 +27,6 @@ import bisq.common.UserThread;
|
|||
import bisq.common.app.AppModule;
|
||||
import bisq.common.app.Capabilities;
|
||||
import bisq.common.app.Capability;
|
||||
import bisq.common.setup.CommonSetup;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -50,7 +49,6 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
|
|||
super.doExecute();
|
||||
|
||||
checkMemory(config, this);
|
||||
CommonSetup.setupUncaughtExceptionHandler(this);
|
||||
|
||||
keepRunning();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import bisq.core.app.misc.ModuleForAppWithP2p;
|
|||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.app.AppModule;
|
||||
import bisq.common.setup.CommonSetup;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -45,7 +44,6 @@ public class StatisticsMain extends ExecutableForAppWithP2p {
|
|||
super.doExecute();
|
||||
|
||||
checkMemory(config, this);
|
||||
CommonSetup.setupUncaughtExceptionHandler(this);
|
||||
|
||||
keepRunning();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue