Class ProxyListFallbackSelector
- java.lang.Object
-
- java.net.ProxySelector
-
- com.github.markusbernhardt.proxy.selector.misc.ProxyListFallbackSelector
-
public class ProxyListFallbackSelector extends java.net.ProxySelectorImplements 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 intDEFAULT_RETRY_DELAYprivate java.net.ProxySelectordelegateprivate java.util.concurrent.ConcurrentHashMap<java.net.SocketAddress,java.lang.Long>failedDelayCacheprivate longretryAfterMs
-
Constructor Summary
Constructors Constructor Description ProxyListFallbackSelector(long retryAfterMs, java.net.ProxySelector delegate)ConstructorProxyListFallbackSelector(java.net.ProxySelector delegate)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcleanupCache()Cleanup the entries from the cache that are no longer unresponsive.voidconnectFailed(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe)connectFailedprivate java.util.List<java.net.Proxy>filterUnresponsiveProxiesFromList(java.util.List<java.net.Proxy> proxyList)Filters out proxies that are not reponding.private booleanisDirect(java.net.Proxy proxy)Checks if the given proxy is representing a direct connection.private booleanisNotUnresponsive(java.net.Proxy proxy)Tests that a given proxy is not "unresponsive".private booleanretryDelayHasPassedBy(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) voidsetRetryAfterMs(long retryAfterMs)Only used for unit testing not part of the public API.java.lang.StringtoString()
-
-
-
Field Detail
-
DEFAULT_RETRY_DELAY
private static final int DEFAULT_RETRY_DELAY
- See Also:
- Constant Field Values
-
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:
connectFailedin classjava.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:
selectin classjava.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:
toStringin classjava.lang.Object
-
-