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 intprivate ProxySelectorprivate ConcurrentHashMap<SocketAddress, Long> private long -
Constructor Summary
ConstructorsConstructorDescriptionProxyListFallbackSelector(long retryAfterMs, ProxySelector delegate) ConstructorProxyListFallbackSelector(ProxySelector delegate) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCleanup the entries from the cache that are no longer unresponsive.voidconnectFailed(URI uri, SocketAddress sa, IOException ioe) connectFailedfilterUnresponsiveProxiesFromList(List<Proxy> proxyList) Filters out proxies that are not reponding.private booleanChecks if the given proxy is representing a direct connection.private booleanisNotUnresponsive(Proxy proxy) Tests that a given proxy is not "unresponsive".private booleanretryDelayHasPassedBy(Long lastFailTime) Checks if the retry delay has passed.select(package private) final voidsetRetryAfterMs(long retryAfterMs) Only used for unit testing not part of the public API.toString()Methods inherited from class 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:
connectFailedin classProxySelector- See Also:
-
select
-
cleanupCache
private void cleanupCache()Cleanup the entries from the cache that are no longer unresponsive. -
filterUnresponsiveProxiesFromList
-
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
-