+ public abstract void runDbus(boolean isDbusSystem, final String busname) throws CommandException;
+
+ public abstract void runHttp(InetSocketAddress address) throws CommandException;
+
+ protected final void runSocket(final SocketHandler socketHandler) {
+ socketHandler.init();
+ this.closeables.add(socketHandler);
+ }
+
+ protected final void runDbus(
+ DbusHandler dbusHandler
+ ) throws CommandException {
+ dbusHandler.init();
+ this.closeables.add(dbusHandler);
+ }
+
+ protected final void runHttp(final HttpServerHandler handler) throws CommandException {
+ try {
+ handler.init();
+ } catch (IOException ex) {
+ throw new IOErrorException("Failed to initialize HTTP Server", ex);
+ }
+ this.closeables.add(handler);
+ }
+
+ @Override
+ public void close() {
+ for (final var closeable : new ArrayList<>(this.closeables)) {
+ try {
+ closeable.close();
+ } catch (Exception e) {
+ logger.warn("Failed to close daemon handler", e);
+ }
+ }
+ this.closeables.clear();
+ }
+ }
+
+ private static final class SingleAccountDaemonHandler extends DaemonHandler {
+
+ private final Manager m;
+
+ public SingleAccountDaemonHandler(final Manager m, final ReceiveMode receiveMode) {
+ super(receiveMode);
+ this.m = m;
+ }
+
+ @Override
+ public void runSocket(final ServerSocketChannel serverChannel) {
+ runSocket(new SocketHandler(serverChannel, m, receiveMode == ReceiveMode.MANUAL));
+ }
+
+ @Override
+ public void runDbus(final boolean isDbusSystem, final String busname) throws CommandException {
+ runDbus(new DbusHandler(isDbusSystem, busname, m, receiveMode != ReceiveMode.ON_START));
+ }
+
+ @Override
+ public void runHttp(InetSocketAddress address) throws CommandException {
+ runHttp(new HttpServerHandler(address, m));
+ }
+ }
+
+ private static final class MultiAccountDaemonHandler extends DaemonHandler {
+
+ private final MultiAccountManager c;
+
+ public MultiAccountDaemonHandler(final MultiAccountManager c, final ReceiveMode receiveMode) {
+ super(receiveMode);
+ this.c = c;
+ }
+
+ @Override
+ public void runSocket(final ServerSocketChannel serverChannel) {
+ runSocket(new SocketHandler(serverChannel, c, receiveMode == ReceiveMode.MANUAL));
+ }
+
+ @Override
+ public void runDbus(final boolean isDbusSystem, final String busname) throws CommandException {
+ runDbus(new DbusHandler(isDbusSystem, busname, c, receiveMode != ReceiveMode.ON_START));
+ }
+
+ @Override
+ public void runHttp(final InetSocketAddress address) throws CommandException {
+ runHttp(new HttpServerHandler(address, c));
+ }