Class ProxyListFallbackSelector

java.lang.Object
java.net.ProxySelector
com.github.markusbernhardt.proxy.selector.misc.ProxyListFallbackSelector

public class ProxyListFallbackSelector extends ProxySelector
Implements a fallback selector to warp it around an existing ProxySelector. This will remove proxies from a list of proxies and implement an automatic retry mechanism.
  • Field Details

  • Constructor Details

    • ProxyListFallbackSelector

      public ProxyListFallbackSelector(ProxySelector delegate)
      Constructor
      Parameters:
      delegate - the delegate to use.
    • ProxyListFallbackSelector

      public ProxyListFallbackSelector(long retryAfterMs, ProxySelector delegate)
      Constructor
      Parameters:
      retryAfterMs - the "retry delay" as amount of milliseconds.
      delegate - the delegate to use.
  • Method Details

    • connectFailed

      public void connectFailed(URI uri, SocketAddress sa, IOException ioe)
      connectFailed
      Specified by:
      connectFailed in class ProxySelector
      See Also:
    • select

      public List<Proxy> select(URI uri)
      select
      Specified by:
      select in class ProxySelector
      See Also:
    • cleanupCache

      private void cleanupCache()
      Cleanup the entries from the cache that are no longer unresponsive.
    • filterUnresponsiveProxiesFromList

      private List<Proxy> filterUnresponsiveProxiesFromList(List<Proxy> proxyList)
      Filters out proxies that are not reponding.
      Parameters:
      proxyList - a list of proxies to test.
      Returns:
      the filtered list.
    • isDirect

      private boolean isDirect(Proxy proxy)
      Checks if the given proxy is representing a direct connection.
      Parameters:
      proxy - to inspect.
      Returns:
      true if it is direct else false.
    • isNotUnresponsive

      private boolean isNotUnresponsive(Proxy proxy)
      Tests that a given proxy is not "unresponsive".
      Parameters:
      proxy - to test.
      Returns:
      true if not unresponsive.
    • retryDelayHasPassedBy

      private boolean retryDelayHasPassedBy(Long lastFailTime)
      Checks if the retry delay has passed.
      Parameters:
      lastFailTime -
      Returns:
      true if the delay has passed.
    • setRetryAfterMs

      final void setRetryAfterMs(long retryAfterMs)
      Only used for unit testing not part of the public API.
      Parameters:
      retryAfterMs - The retryAfterMs to set.
    • toString

      public String toString()
      Overrides:
      toString in class Object