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
This commit is contained in:
jiaz 2024-09-26 15:44:58 +00:00
parent e2c5dcbff6
commit 5a1b54cc8d

View File

@ -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<Object, Map<String, UnavailableHost>> 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<Object, Map<String, UnavailableHost>> db = getDB();
synchronized (db) {
db.remove(event.getAccount());
}
}
break;
default:
break;
}
}
}