From 9abd452cd2508bb97c0304e1c13f61ac9f17355b Mon Sep 17 00:00:00 2001 From: Alon Albert Date: Tue, 2 Jan 2018 13:33:25 +0200 Subject: [PATCH] Combine multiple requests into a single one in doRetrieve. Support version for priority conversions --- .../daemon/Deluge/DelugeRpcAdapter.java | 255 ++++++++++-------- .../daemon/Deluge/DelugeRpcClient.java | 9 +- 2 files changed, 150 insertions(+), 114 deletions(-) diff --git a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java index cf0c34fc..c598b5f1 100644 --- a/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java @@ -26,6 +26,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -78,7 +79,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { public static final int DEFAULT_PORT = 58846; // TODO: Extract constants to a common file used by both Adapters. - // private static final String RPC_METHOD_INFO = "daemon.info"; + private static final String RPC_METHOD_INFO = "daemon.info"; private static final String RPC_METHOD_GET_TORRENTS_STATUS = "core.get_torrents_status"; private static final String RPC_METHOD_STATUS = "core.get_torrent_status"; private static final String RPC_METHOD_GET_LABELS = "label.get_labels"; @@ -167,6 +168,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { private final DaemonSettings settings; + private int version = -1; + public DelugeRpcAdapter(DaemonSettings settings) { this.settings = settings; } @@ -235,13 +238,23 @@ public class DelugeRpcAdapter implements IDaemonAdapter { } @NonNull - private RetrieveTaskSuccessResult doRetrieve(DelugeRpcClient client, - RetrieveTask task) throws DaemonException { + private RetrieveTaskSuccessResult doRetrieve(DelugeRpcClient client, RetrieveTask task) + throws DaemonException { - final List torrents = getTorrents(client); - return new RetrieveTaskSuccessResult(task, torrents, getLabels(client, torrents)); - } + final List results = client.sendRequests( + new Request(RPC_METHOD_INFO), + new Request(RPC_METHOD_GET_TORRENTS_STATUS, new HashMap<>(), TORRENT_FIELDS), + new Request(RPC_METHOD_GET_LABELS)); + setVersion((String) results.get(0)); + //noinspection unchecked + final Map> torrentsStatus = (Map>) results + .get(1); + final List torrents = getTorrents(torrentsStatus.values()); + //noinspection unchecked + final List