From 5a1b54cc8d74f987ebca8d7f85211260cf1ecc5b Mon Sep 17 00:00:00 2001 From: jiaz Date: Thu, 26 Sep 2024 15:44:58 +0000 Subject: [PATCH] MultiHosterManagement: -implements AccountControllerListener, auto clear entry when account is updated/refreshed git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@49876 ebf7c1c2-ba36-0410-9fe8-c592906822b4 Former-commit-id: 9eead6d9a7d0708c6f9a546d5da558271c429259 --- .../components/MultiHosterManagement.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/jd/plugins/components/MultiHosterManagement.java b/src/jd/plugins/components/MultiHosterManagement.java index 6363d8c884..d958d6a26c 100644 --- a/src/jd/plugins/components/MultiHosterManagement.java +++ b/src/jd/plugins/components/MultiHosterManagement.java @@ -3,11 +3,10 @@ package jd.plugins.components; import java.util.HashMap; import java.util.Map; -import org.appwork.exceptions.WTFException; -import org.appwork.utils.DebugMode; -import org.appwork.utils.Time; - import jd.config.Property; +import jd.controlling.AccountController; +import jd.controlling.AccountControllerEvent; +import jd.controlling.AccountControllerListener; import jd.plugins.Account; import jd.plugins.AccountInfo; import jd.plugins.DownloadLink; @@ -16,6 +15,10 @@ import jd.plugins.MultiHostHost; import jd.plugins.Plugin; import jd.plugins.PluginException; +import org.appwork.exceptions.WTFException; +import org.appwork.utils.DebugMode; +import org.appwork.utils.Time; + /** * Instead of duplication we create a class * @@ -24,7 +27,7 @@ import jd.plugins.PluginException; * @author raztoki * */ -public class MultiHosterManagement { +public class MultiHosterManagement implements AccountControllerListener { private final String host; public MultiHosterManagement(final String host) { @@ -60,6 +63,9 @@ public class MultiHosterManagement { } public void putError(final Object account, final DownloadLink downloadLink, final Long timeout, final String reason) throws PluginException { + if (account instanceof Account) { + AccountController.getInstance().getEventSender().addListener(this, true); + } final Map> db = getDB(); synchronized (db) { // null(multihosterwide) && AccountType && Account @@ -190,4 +196,21 @@ public class MultiHosterManagement { this.putError(account, downloadLink, errorWait, "Exhausted retry count: " + error); } } + + @Override + public void onAccountControllerEvent(AccountControllerEvent event) { + switch (event.getType()) { + case ACCOUNT_CHECKED: + case ACCOUNT_PROPERTY_UPDATE: + if (event.getAccount().isValid()) { + final Map> db = getDB(); + synchronized (db) { + db.remove(event.getAccount()); + } + } + break; + default: + break; + } + } }