-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from PBH-BTN/master
v5.0.4
- Loading branch information
Showing
21 changed files
with
153 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/ghostchu/peerbanhelper/downloader/AbstractDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.ghostchu.peerbanhelper.downloader; | ||
|
||
import com.ghostchu.peerbanhelper.text.Lang; | ||
import com.ghostchu.peerbanhelper.text.TranslationComponent; | ||
import com.ghostchu.peerbanhelper.util.MsgUtil; | ||
|
||
import java.util.Date; | ||
|
||
public abstract class AbstractDownloader implements Downloader { | ||
protected String name; | ||
private DownloaderLastStatus lastStatus = DownloaderLastStatus.UNKNOWN; | ||
private TranslationComponent statusMessage; | ||
private int failedLoginAttempts = 0; | ||
private long nextLoginTry = 0L; | ||
|
||
public AbstractDownloader(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public DownloaderLoginResult login() { | ||
if (nextLoginTry >= System.currentTimeMillis()) { | ||
return new DownloaderLoginResult(DownloaderLoginResult.Status.REQUIRE_TAKE_ACTIONS | ||
, new TranslationComponent(Lang.TOO_MANY_FAILED_ATTEMPT, MsgUtil.getDateFormatter().format(new Date(nextLoginTry))) | ||
); | ||
} | ||
DownloaderLoginResult result; | ||
try { | ||
result = login0(); | ||
if (result.success()) { | ||
failedLoginAttempts = 0; | ||
return result; | ||
} | ||
failedLoginAttempts++; | ||
return result; | ||
} catch (Throwable e) { | ||
failedLoginAttempts++; | ||
throw e; | ||
} finally { | ||
if (failedLoginAttempts >= 15) { | ||
nextLoginTry = System.currentTimeMillis() + (1000 * 60 * 30); | ||
failedLoginAttempts = 0; | ||
} | ||
} | ||
} | ||
|
||
public abstract DownloaderLoginResult login0(); | ||
|
||
@Override | ||
public DownloaderLastStatus getLastStatus() { | ||
return lastStatus; | ||
} | ||
|
||
@Override | ||
public void setLastStatus(DownloaderLastStatus lastStatus, TranslationComponent statusMessage) { | ||
this.lastStatus = lastStatus; | ||
this.statusMessage = statusMessage; | ||
} | ||
|
||
@Override | ||
public TranslationComponent getLastStatusMessage() { | ||
return statusMessage; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.