RetryPolicyFactory

Overview

Class used to create simple Retry Policies. See the RetryPolicy page for more details on what a RetryPolicy does. This class is found in the com.screenscraper.util.retry package.

getBasicPolicy

RetryPolicy RetryPolicyFactory.getBasicPolicy ( int retries, String scriptOnFail )
RetryPolicy RetryPolicyFactory.getBasicPolicy ( int retries, Runnable runnableOnFail )

Description

Policy that retries if there was an error on the request by status code. Executes the runnable given before retrying.

Parameters

  • retries How many times max to retry before failing
  • scriptOnFail/runnableOnFail What to run (script or Runnable) if the policy shows an error on the page. This will be run just before the page is downloaded again. The script or Runnable will be executed in the current thread, so the scrapeable file will not be redownloaded until this runnable or script has finished executing.

Return Value

The RetryPolicy to set in the ScrapeableFile

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Set a basic retry policy

 import com.screenscraper.util.retry.RetryPolicyFactory;
 scrapeableFile.setRetryPolicy(RetryPolicyFactory.getBasicPolicy(5, "Rotate Proxy"));

getEmptyPolicy

RetryPolicy RetryPolicyFactory.getEmptyPolicy ( )

Description

Policy that returns no error. Useful for having a session-wide retry policy, but then using this for a particular scrapeable file so it doesn't use the session's policy

Parameters

    This method takes no parameters

Return Value

The RetryPolicy to set in the ScrapeableFile

Change Log

Version Description
6.0.25a Available in all editions.

Examples

Set an empty retry policy

 import com.screenscraper.util.retry.RetryPolicyFactory;
 scrapeableFile.setRetryPolicy(RetryPolicyFactory.getEmptyPolicy());

getMatchingRegexPolicy

RetryPolicy RetryPolicyFactory.getMatchingRegexPolicy ( int retries, String regex )
RetryPolicy RetryPolicyFactory.getMatchingRegexPolicy ( int retries, String regex, String scriptOnFail )
RetryPolicy RetryPolicyFactory.getMatchingRegexPolicy ( int retries, String regex, Runnable runnableOnFail )

Description

Policy that requires a Regular Expression to match the page content (including headers) in order to be considered valid.

Parameters

  • retries How many times max to retry before failing
  • regex A Regular expression that must match the page content for the page to be considered valid
  • scriptOnFail/runnableOnFail (optional) What to run (script or Runnable) if the policy shows an error on the page. This will be run just before the page is downloaded again. The script or Runnable will be executed in the current thread, so the scrapeable file will not be redownloaded until this runnable or script has finished executing.

Return Value

The RetryPolicy to set in the ScrapeableFile

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Set a matching regex policy

 import com.screenscraper.util.retry.RetryPolicyFactory;
 // Require the response to contain the text "Google.com".  Since this is a regex, the . must have a \ before it
 scrapeableFile.setRetryPolicy(RetryPolicyFactory.getMatchingRegexPolicy(5, "Google\\.com", "Rotate Proxy"));

getMissingRegexPolicy

RetryPolicy RetryPolicyFactory.getMissingRegexPolicy ( int retries, String regex )
RetryPolicy RetryPolicyFactory.getMissingRegexPolicy ( int retries, String regex, String scriptOnFail )
RetryPolicy RetryPolicyFactory.getMissingRegexPolicy ( int retries, String regex, Runnable runnableOnFail )

Description

Policy that requires a Regular Expression NOT to match the page content (including headers) in order to be considered valid. In other words, if the Regular Expression matches, it means that the page should be rescraped.

Parameters

  • retries How many times max to retry before failing
  • regex A Regular expression that must NOT match the page content for the page to be considered valid
  • scriptOnFail/runnableOnFail (optional) What to run (script or Runnable) if the policy shows an error on the page. This will be run just before the page is downloaded again. The script or Runnable will be executed in the current thread, so the scrapeable file will not be redownloaded until this runnable or script has finished executing.

Return Value

The RetryPolicy to set in the ScrapeableFile

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Set a matching regex policy

 import com.screenscraper.util.retry.RetryPolicyFactory;
 // Require the response to not contain the text "Google.com".  Since this is a regex, the . must have a \ before it
 scrapeableFile.setRetryPolicy(RetryPolicyFactory.getMissingRegexPolicy(5, "Google\\.com", "Rotate Proxy"));