This commit is contained in:
Sebastian Stenzel
2021-07-15 08:36:37 +02:00
parent fe84783fac
commit 8271428d64
3 changed files with 11 additions and 8 deletions
@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
@@ -84,4 +85,12 @@ public interface IpcCommunicator extends Closeable {
*/
@Override
void close() throws IOException;
default void closeUnchecked() throws UncheckedIOException {
try {
close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
@@ -76,6 +76,7 @@ class Server implements IpcCommunicator {
serverSocketChannel.close();
} finally {
Files.deleteIfExists(socketPath);
LOG.debug("IPC server closed");
}
}
}
@@ -83,14 +83,7 @@ public class Cryptomator {
LOG.info("Found running application instance. Shutting down...");
return 2;
} else {
// TODO: move this to a better place?
shutdownHook.runOnShutdown(() -> {
try {
communicator.close();
} catch (IOException e) {
LOG.warn("IPC cleanup failed");
}
});
shutdownHook.runOnShutdown(communicator::closeUnchecked);
var executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("IPC-%d").build());
var msgHandler = ipcMessageHandler.get();
msgHandler.handleLaunchArgs(List.of(args));