import java.io.IOException;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.TimeUnit;
public class DaemonCommand implements MultiLocalCommand {
private final static Logger logger = LoggerFactory.getLogger(DaemonCommand.class);
- private final OutputWriter outputWriter;
- public static void attachToSubparser(final Subparser subparser) {
+ @Override
+ public String getName() {
+ return "daemon";
+ }
+
+ @Override
+ public void attachToSubparser(final Subparser subparser) {
subparser.help("Run in daemon mode and provide an experimental dbus interface.");
subparser.addArgument("--system")
.action(Arguments.storeTrue())
.action(Arguments.storeTrue());
}
- public DaemonCommand(final OutputWriter outputWriter) {
- this.outputWriter = outputWriter;
- }
-
@Override
- public Set<OutputType> getSupportedOutputTypes() {
- return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
+ public List<OutputType> getSupportedOutputTypes() {
+ return List.of(OutputType.PLAIN_TEXT, OutputType.JSON);
}
@Override
- public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
+ public void handleCommand(
+ final Namespace ns, final Manager m, final OutputWriter outputWriter
+ ) throws CommandException {
boolean ignoreAttachments = ns.getBoolean("ignore-attachments");
DBusConnection.DBusBusType busType;
try (var conn = DBusConnection.getConnection(busType)) {
var objectPath = DbusConfig.getObjectPath();
- var t = run(conn, objectPath, m, ignoreAttachments);
+ var t = run(conn, objectPath, m, outputWriter, ignoreAttachments);
conn.requestBusName(DbusConfig.getBusname());
}
} catch (DBusException | IOException e) {
logger.error("Dbus command failed", e);
- throw new UnexpectedErrorException("Dbus command failed");
+ throw new UnexpectedErrorException("Dbus command failed", e);
}
}
@Override
public void handleCommand(
- final Namespace ns, final List<Manager> managers, SignalCreator c
+ final Namespace ns, final List<Manager> managers, final SignalCreator c, final OutputWriter outputWriter
) throws CommandException {
boolean ignoreAttachments = ns.getBoolean("ignore-attachments");
final var signalControl = new DbusSignalControlImpl(c, m -> {
try {
final var objectPath = DbusConfig.getObjectPath(m.getUsername());
- return run(conn, objectPath, m, ignoreAttachments);
+ return run(conn, objectPath, m, outputWriter, ignoreAttachments);
} catch (DBusException e) {
logger.error("Failed to export object", e);
return null;
signalControl.run();
} catch (DBusException | IOException e) {
logger.error("Dbus command failed", e);
- throw new UnexpectedErrorException("Dbus command failed");
+ throw new UnexpectedErrorException("Dbus command failed", e);
}
}
private Thread run(
- DBusConnection conn, String objectPath, Manager m, boolean ignoreAttachments
+ DBusConnection conn, String objectPath, Manager m, OutputWriter outputWriter, boolean ignoreAttachments
) throws DBusException {
conn.exportObject(new DbusSignalImpl(m, objectPath));
break;
} catch (IOException e) {
logger.warn("Receiving messages failed, retrying", e);
- } catch (InterruptedException ignored) {
- break;
}
}
});