- boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
- try {
- m.receiveMessages(1,
- TimeUnit.HOURS,
- false,
- ignoreAttachments,
- inJson
- ? new JsonDbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH)
- : new DbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH));
- return 0;
- } catch (IOException e) {
- System.err.println("Error while receiving messages: " + e.getMessage());
- return 3;
- } catch (AssertionError e) {
- handleAssertionError(e);
- return 1;
+ return 0;
+ } catch (DBusException | IOException e) {
+ logger.error("Dbus command failed", e);
+ return 2;
+ }
+ }
+
+ @Override
+ public int handleCommand(final Namespace ns, final List<Manager> managers) {
+ boolean inJson = ns.getString("output").equals("json") || ns.getBoolean("json");
+
+ // TODO delete later when "json" variable is removed
+ if (ns.getBoolean("json")) {
+ logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
+ }
+
+ boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
+
+ DBusConnection.DBusBusType busType;
+ if (ns.getBoolean("system")) {
+ busType = DBusConnection.DBusBusType.SYSTEM;
+ } else {
+ busType = DBusConnection.DBusBusType.SESSION;
+ }
+
+ try (DBusConnection conn = DBusConnection.getConnection(busType)) {
+ List<Thread> receiveThreads = new ArrayList<>();
+ for (Manager m : managers) {
+ String objectPath = DbusConfig.getObjectPath(m.getUsername());
+ Thread thread = run(conn, objectPath, m, ignoreAttachments, inJson);
+ receiveThreads.add(thread);