Class BufferedProxySelector
- java.lang.Object
-
- java.net.ProxySelector
-
- com.github.markusbernhardt.proxy.selector.misc.BufferedProxySelector
-
public class BufferedProxySelector extends java.net.ProxySelector
Implements a cache that can be used to warp it around an existing ProxySelector. You can specify a maximum cache size and a "time to live" for positive resolves.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BufferedProxySelector.CacheEntry
static class
BufferedProxySelector.CacheScope
Define the available scopes of the cache key generation
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentHashMap<java.lang.String,BufferedProxySelector.CacheEntry>
cache
private BufferedProxySelector.CacheScope
cacheScope
private java.net.ProxySelector
delegate
private int
maxSize
private long
ttl
-
Constructor Summary
Constructors Constructor Description BufferedProxySelector(int maxSize, long ttl, java.net.ProxySelector delegate, BufferedProxySelector.CacheScope cacheScope)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectFailed(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe)
connectFailedprivate void
purgeCache()
Purge cache to get some free space for a new entry.java.util.List<java.net.Proxy>
select(java.net.URI uri)
selectjava.lang.String
toString()
-
-
-
Field Detail
-
delegate
private java.net.ProxySelector delegate
-
cache
private java.util.concurrent.ConcurrentHashMap<java.lang.String,BufferedProxySelector.CacheEntry> cache
-
maxSize
private int maxSize
-
ttl
private long ttl
-
cacheScope
private BufferedProxySelector.CacheScope cacheScope
-
-
Constructor Detail
-
BufferedProxySelector
public BufferedProxySelector(int maxSize, long ttl, java.net.ProxySelector delegate, BufferedProxySelector.CacheScope cacheScope)
Constructor- Parameters:
maxSize
- the max size for the cache.ttl
- the "time to live" for cache entries as amount in milliseconds.delegate
- the delegate to use.cacheScope
- the desired cache scope.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
connectFailed
public void connectFailed(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe)
connectFailed- Specified by:
connectFailed
in 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:
select
in classjava.net.ProxySelector
- See Also:
ProxySelector.select(java.net.URI)
-
purgeCache
private void purgeCache()
Purge cache to get some free space for a new entry.
-
-