public class MultiplePolicyRetryPolicy extends AbstractRetryPolicy
Modifier and Type | Class and Description |
---|---|
static class |
MultiplePolicyRetryPolicy.Operator |
errorOutputMap, maxNumberOfRetries, resetReferrerBeforeRescrape, resetSessionVariablesBeforeRescrape, scrapingSession, scriptContext, theScrapeableFile
Constructor and Description |
---|
MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator,
boolean forceRunAll,
java.util.List<RetryPolicy> policies)
Creates a retry policy based on the policies in the given list.
|
MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator,
boolean forceRunAll,
RetryPolicy... policies)
Creates a retry policy based on the policies in the given array.
|
MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator,
java.util.List<RetryPolicy> policies)
Creates a retry policy based on the policies in the given list.
|
MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator,
RetryPolicy... policies)
Creates a retry policy based on the policies in the given array.
|
Modifier and Type | Method and Description |
---|---|
AbstractRetryPolicy |
duplicate()
Duplicates this retry policy, copying any needed values to the new AbstractRetryPolicy.
|
int |
getMaxRetryAttempts()
This method will return the minimum of any of it's contained policies' retry counts Return the maximum number of times this policy allows for a retry before terminating in an error
|
boolean |
isError()
Checks to see if the page loaded incorrectly
|
boolean |
resetReferrerBeforeRescrape()
Returns true if the referrer should be reset before attempting to rescrape the file, if there was an error.
|
boolean |
resetSessionVariablesBeforeRescrape()
Returns true if the session variables should be reset before attempting to rescrape the file, if there was an error.
|
void |
runOnAllAttemptsFailed()
This will be called if all the retry attempts for the scrapeable file failed.
|
void |
runOnError()
Runs this code when the page had an error.
|
void |
setScrapeableFile(ScrapeableFile scrapeableFile)
Sets the scrapeable file this policy will use to get the downloaded content
|
void |
setScrapingSession(ScrapingSession session)
Sets the scraping session for this policy to access, if need be
|
boolean |
shouldLogErrors()
Returns true if errors should be logged to the log/web interface when they occur
|
getErrorChecksMap, getScriptContext, setMaxNumberOfRetries, setResetReferrerBeforeRescrape, setResetSessionVariablesBeforeRescrape, setScriptContext
public MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator, RetryPolicy... policies)
operator
- The operator used to combine the error checks from each policypolicies
- The policies to use togetherpublic MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator, boolean forceRunAll, RetryPolicy... policies)
operator
- The operator used to combine the error checks from each policyforceRunAll
- True if an error by this policy should run the error handling code for all sub policies, false otherwisepolicies
- The policies to use togetherpublic MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator, java.util.List<RetryPolicy> policies)
operator
- The operator used to combine the error checks from each policypolicies
- The policies to use togetherpublic MultiplePolicyRetryPolicy(MultiplePolicyRetryPolicy.Operator operator, boolean forceRunAll, @Nullable java.util.List<RetryPolicy> policies)
operator
- The operator used to combine the error checks from each policyforceRunAll
- True if an error by this policy should run the error handling code for all sub policies, false otherwisepolicies
- The policies to use togetherpublic void setScrapeableFile(ScrapeableFile scrapeableFile)
AbstractRetryPolicy
setScrapeableFile
in class AbstractRetryPolicy
scrapeableFile
- The scrapeable file to usepublic void setScrapingSession(ScrapingSession session)
AbstractRetryPolicy
setScrapingSession
in class AbstractRetryPolicy
session
- The current scraping sessionpublic boolean isError() throws java.lang.Exception
RetryPolicy
isError
in interface RetryPolicy
isError
in class AbstractRetryPolicy
java.lang.Exception
- If something goes wrong while executing this methodpublic void runOnError() throws java.lang.Exception
RetryPolicy
java.lang.Exception
- If something goes wrong while executing this methodpublic boolean resetSessionVariablesBeforeRescrape()
RetryPolicy
RetryPolicy.runOnError()
resetSessionVariablesBeforeRescrape
in interface RetryPolicy
resetSessionVariablesBeforeRescrape
in class AbstractRetryPolicy
public boolean resetReferrerBeforeRescrape()
RetryPolicy
RetryPolicy.runOnError()
resetReferrerBeforeRescrape
in interface RetryPolicy
resetReferrerBeforeRescrape
in class AbstractRetryPolicy
public boolean shouldLogErrors()
RetryPolicy
shouldLogErrors
in interface RetryPolicy
shouldLogErrors
in class AbstractRetryPolicy
public int getMaxRetryAttempts()
getMaxRetryAttempts
in interface RetryPolicy
getMaxRetryAttempts
in class AbstractRetryPolicy
public void runOnAllAttemptsFailed() throws java.lang.Exception
RetryPolicy.runOnError()
will be called just before this, as it is called after each time the scrapeable file fails to load
correctly, including the last time it fails to load.
This should only contain code that handles the final error. Any proxy rotating, cookie clearing, etc... should generally be done in the RetryPolicy.runOnError()
method, especially since it will still be called after the final error.
This method will only call the runOnAllAttemptsFailed method for policies that show an error on the current check.runOnAllAttemptsFailed
in interface RetryPolicy
runOnAllAttemptsFailed
in class AbstractRetryPolicy
java.lang.Exception
public AbstractRetryPolicy duplicate()
AbstractRetryPolicy
Note that the copy can share internal references if necessary for the functionality of the policy. For example, if the policy is tracking total number of failures
it may have a shared AtomicInteger
reference for counting, which is passed in to the duplicate policy by reference. Therefore, duplicate isn't necessarily
an independent duplicate. It should be noted though that a "duplicate" copy of the policy is used for each scrapeable file when called
duplicate
in class AbstractRetryPolicy