*General*

- MultiHosterManagement: added MultiHostHost wrapper-implementation
- MultiHostHost: getStatusText: simplified method to be a simple getter

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@49865 ebf7c1c2-ba36-0410-9fe8-c592906822b4

Former-commit-id: de1d434e44728a89941b860bed1429cd28bce727
This commit is contained in:
psp 2024-09-25 14:00:49 +00:00
parent 5965c89a87
commit eec0b253b6
3 changed files with 23 additions and 12 deletions

View File

@ -109,7 +109,7 @@ public class MultiHostHost implements Storable {
this.isUnlimitedLinks = false;
}
/** Only do this when linksMax is given. */
/** Only use this when linksMax is given!! */
public void setLinksUsed(long num) {
this.linksLeft = this.linksMax - num;
this.isUnlimitedLinks = false;
@ -182,14 +182,9 @@ public class MultiHostHost implements Storable {
}
}
/** Returns custom set status text. Typically used to describe why this host is currently not working. */
public String getStatusText() {
if (this.statusText != null) {
return statusText;
} else if (status != null) {
return status.name();
} else {
return null;
}
return statusText;
}
public void setStatusText(String statusText) {
@ -197,6 +192,7 @@ public class MultiHostHost implements Storable {
}
public MultihosterHostStatus getStatus() {
// TODO: Update this to simply return status without any evaluation
if (this.unavailableUntilTimestamp > Time.systemIndependentCurrentJVMTimeMillis()) {
return MultihosterHostStatus.DEACTIVATED_JDOWNLOADER;
} else if (status == null) {

View File

@ -4,6 +4,7 @@ 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;
@ -62,7 +63,7 @@ public class MultiHosterManagement {
final Map<Object, Map<String, UnavailableHost>> db = getDB();
synchronized (db) {
// null(multihosterwide) && AccountType && Account
final UnavailableHost nue = new UnavailableHost(Time.systemIndependentCurrentJVMTimeMillis() + timeout, reason);
final UnavailableHost nue = new UnavailableHost(reason, Time.systemIndependentCurrentJVMTimeMillis() + timeout);
Map<String, UnavailableHost> unavailableMap = db.get(account);
if (unavailableMap == null) {
unavailableMap = new HashMap<String, UnavailableHost>();
@ -81,6 +82,7 @@ public class MultiHosterManagement {
/* Host might have been removed from list of supported hosts in the meantime. */
break setLimitOnAccount;
}
mhost.setStatusText(reason);
mhost.setUnavailableTime(timeout);
ai.updateMultihostSupportedHost(mhost);
}
@ -101,6 +103,11 @@ public class MultiHosterManagement {
synchronized (db) {
// check for null(multihosterwide) first, AccountTypes(specific to this account type) second, and Account (specific to this
// account) last!
MultiHostHost mhost = null;
final AccountInfo ai = account.getAccountInfo();
if (ai != null) {
mhost = ai.getMultihostSupportedHost(downloadLink.getHost());
}
final Object[] acc = new Object[] { null, account.getType(), account };
for (final Object ob : acc) {
final Map<String, UnavailableHost> unavailableMap = db.get(ob);
@ -108,8 +115,16 @@ public class MultiHosterManagement {
if (nue == null) {
continue;
}
final Long lastUnavailable = nue.getErrorTimeout();
final String errorReason = nue.getErrorReason();
String errorReason = nue.getErrorReason();
Long lastUnavailable = nue.getErrorTimeout();
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE && mhost != null) {
if (mhost.getStatusText() != null) {
errorReason = mhost.getStatusText();
}
if (mhost.getUnavailableUntilTimestamp() != -1) {
lastUnavailable = mhost.getUnavailableUntilTimestamp();
}
}
if (lastUnavailable == null) {
// never can download from
throw new PluginException(LinkStatus.ERROR_FATAL, "Not possible to download from " + downloadLink.getHost());

View File

@ -12,7 +12,7 @@ public final class UnavailableHost {
private String errorReason;
private Long errorTimeout;
public UnavailableHost(final Long errorTimeout, final String errorReason) {
public UnavailableHost(final String errorReason, final Long errorTimeout) {
this.errorTimeout = errorTimeout;
this.errorReason = errorReason;
}