Class ProxyListFallbackSelector
java.lang.Object
java.net.ProxySelector
com.github.markusbernhardt.proxy.selector.misc.ProxyListFallbackSelector
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
FieldsModifier and TypeFieldDescriptionprivate static final int
private ProxySelector
private ConcurrentHashMap
<SocketAddress, Long> private long
-
Constructor Summary
ConstructorsConstructorDescriptionProxyListFallbackSelector
(long retryAfterMs, ProxySelector delegate) ConstructorProxyListFallbackSelector
(ProxySelector delegate) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Cleanup the entries from the cache that are no longer unresponsive.void
connectFailed
(URI uri, SocketAddress sa, IOException ioe) connectFailedfilterUnresponsiveProxiesFromList
(List<Proxy> proxyList) Filters out proxies that are not reponding.private boolean
Checks if the given proxy is representing a direct connection.private boolean
isNotUnresponsive
(Proxy proxy) Tests that a given proxy is not "unresponsive".private boolean
retryDelayHasPassedBy
(Long lastFailTime) Checks if the retry delay has passed.select(package private) final void
setRetryAfterMs
(long retryAfterMs) Only used for unit testing not part of the public API.toString()
Methods inherited from class java.net.ProxySelector
getDefault, of, setDefault
-
Field Details
-
DEFAULT_RETRY_DELAY
private static final int DEFAULT_RETRY_DELAY- See Also:
-
delegate
-
failedDelayCache
-
retryAfterMs
private long retryAfterMs
-
-
Constructor Details
-
ProxyListFallbackSelector
Constructor- Parameters:
delegate
- the delegate to use.
-
ProxyListFallbackSelector
Constructor- Parameters:
retryAfterMs
- the "retry delay" as amount of milliseconds.delegate
- the delegate to use.
-
-
Method Details
-
connectFailed
connectFailed- Specified by:
connectFailed
in classProxySelector
- See Also:
-
select
select- Specified by:
select
in classProxySelector
- See Also:
-
cleanupCache
private void cleanupCache()Cleanup the entries from the cache that are no longer unresponsive. -
filterUnresponsiveProxiesFromList
Filters out proxies that are not reponding.- Parameters:
proxyList
- a list of proxies to test.- Returns:
- the filtered list.
-
isDirect
Checks if the given proxy is representing a direct connection.- Parameters:
proxy
- to inspect.- Returns:
- true if it is direct else false.
-
isNotUnresponsive
Tests that a given proxy is not "unresponsive".- Parameters:
proxy
- to test.- Returns:
- true if not unresponsive.
-
retryDelayHasPassedBy
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
-