mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Extend shutdown request with optional error
This commit is contained in:
parent
e7ca02f1fb
commit
069325af47
2 changed files with 13 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
package org.asamk.signal;
|
package org.asamk.signal;
|
||||||
|
|
||||||
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ import sun.misc.Signal;
|
||||||
public class Shutdown {
|
public class Shutdown {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Shutdown.class);
|
private static final Logger logger = LoggerFactory.getLogger(Shutdown.class);
|
||||||
private static final CompletableFuture<Void> shutdown = new CompletableFuture<>();
|
private static final CompletableFuture<Object> shutdown = new CompletableFuture<>();
|
||||||
private static final CompletableFuture<Void> shutdownComplete = new CompletableFuture<>();
|
private static final CompletableFuture<Void> shutdownComplete = new CompletableFuture<>();
|
||||||
private static boolean initialized = false;
|
private static boolean initialized = false;
|
||||||
|
|
||||||
|
@ -43,9 +44,17 @@ public class Shutdown {
|
||||||
shutdown.complete(null);
|
shutdown.complete(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void waitForShutdown() throws InterruptedException {
|
public static void triggerShutdown(CommandException exception) {
|
||||||
|
logger.debug("Triggering shutdown with exception.", exception);
|
||||||
|
shutdown.complete(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void waitForShutdown() throws InterruptedException, CommandException {
|
||||||
try {
|
try {
|
||||||
shutdown.get();
|
final var result = shutdown.get();
|
||||||
|
if (result instanceof CommandException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
|
||||||
final OutputWriter outputWriter
|
final OutputWriter outputWriter
|
||||||
) throws CommandException {
|
) throws CommandException {
|
||||||
Shutdown.installHandler();
|
Shutdown.installHandler();
|
||||||
logger.info("Starting daemon in single-account mode for " + m.getSelfNumber());
|
logger.info("Starting daemon in single-account mode for {}", m.getSelfNumber());
|
||||||
final var noReceiveStdOut = Boolean.TRUE.equals(ns.getBoolean("no-receive-stdout"));
|
final var noReceiveStdOut = Boolean.TRUE.equals(ns.getBoolean("no-receive-stdout"));
|
||||||
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
|
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
|
||||||
final var receiveConfig = getReceiveConfig(ns);
|
final var receiveConfig = getReceiveConfig(ns);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue