Class ProxyListFallbackSelector


  • public class ProxyListFallbackSelector
    extends java.net.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 Summary

      Fields 
      Modifier and Type Field Description
      private static int DEFAULT_RETRY_DELAY  
      private java.net.ProxySelector delegate  
      private java.util.concurrent.ConcurrentHashMap<java.net.SocketAddress,​java.lang.Long> failedDelayCache  
      private long retryAfterMs  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void cleanupCache()
      Cleanup the entries from the cache that are no longer unresponsive.
      void connectFailed​(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe)
      connectFailed
      private java.util.List<java.net.Proxy> filterUnresponsiveProxiesFromList​(java.util.List<java.net.Proxy> proxyList)
      Filters out proxies that are not reponding.
      private boolean isDirect​(java.net.Proxy proxy)
      Checks if the given proxy is representing a direct connection.
      private boolean isNotUnresponsive​(java.net.Proxy proxy)
      Tests that a given proxy is not "unresponsive".
      private boolean retryDelayHasPassedBy​(java.lang.Long lastFailTime)
      Checks if the retry delay has passed.
      java.util.List<java.net.Proxy> select​(java.net.URI uri)
      select
      (package private) void setRetryAfterMs​(long retryAfterMs)
      Only used for unit testing not part of the public API.
      java.lang.String toString()  
      • Methods inherited from class java.net.ProxySelector

        getDefault, of, setDefault
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • delegate

        private java.net.ProxySelector delegate
      • failedDelayCache

        private java.util.concurrent.ConcurrentHashMap<java.net.SocketAddress,​java.lang.Long> failedDelayCache
      • retryAfterMs

        private long retryAfterMs
    • Constructor Detail

      • ProxyListFallbackSelector

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

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

      • connectFailed

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

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

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

        private java.util.List<java.net.Proxy> filterUnresponsiveProxiesFromList​(java.util.List<java.net.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​(java.net.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​(java.net.Proxy proxy)
        Tests that a given proxy is not "unresponsive".
        Parameters:
        proxy - to test.
        Returns:
        true if not unresponsive.
      • retryDelayHasPassedBy

        private boolean retryDelayHasPassedBy​(java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object