Package com.github.markusbernhardt.proxy
Class ProxySearch
- java.lang.Object
-
- com.github.markusbernhardt.proxy.ProxySearch
-
- All Implemented Interfaces:
ProxySearchStrategy
public class ProxySearch extends Object implements ProxySearchStrategy
Main class to setup and initialize the proxy detection system.
This class can be used to select a proxy discovery strategy.
Implements the "Builder" pattern.
UseaddStrategyto add one or more search strategies.
If you are done call thegetProxySelectormethod.
Then the strategies are asked one after the other for a ProxySelector until an valid selector is found.
Invoke the static
getDefaultProxySearchmethod to use a default search strategy.- Author:
- Markus Bernhardt, Copyright 2016, Bernd Rosstauscher, Copyright 2009
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProxySearch.StrategyTypes of proxy detection supported by the builder.
-
Constructor Summary
Constructors Constructor Description ProxySearch()Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStrategy(ProxySearch.Strategy strategy)Adds an search strategy to the list of proxy searches strategies.voidaddStrategy(ProxySearchStrategy customStrategy, boolean addAsFirst)Adds an search strategy to the list of proxy searches strategies.static ProxySearchgetDefaultProxySearch()Sets up a ProxySearch that uses a default search strategy suitable for every platform.StringgetName()Gets the printable name of the search strategy.ProxySelectorgetProxySelector()Gets the proxy selector that will use the configured search order.static voidmain(String[] args)For testing only.voidremoveStrategy(ProxySearch.Strategy strategy)Removes a search strategy from the list of proxy searches strategies.voidsetPacCacheSettings(int size, long ttl, BufferedProxySelector.CacheScope cacheScope)Sets the cache size of the PAC proxy selector cache.StringtoString()toString
-
-
-
Method Detail
-
getDefaultProxySearch
public static ProxySearch getDefaultProxySearch()
Sets up a ProxySearch that uses a default search strategy suitable for every platform.- Returns:
- a ProxySearch initialized with default settings.
-
addStrategy
public void addStrategy(ProxySearch.Strategy strategy)
Adds an search strategy to the list of proxy searches strategies.- Parameters:
strategy- the search strategy to add.
-
addStrategy
public void addStrategy(ProxySearchStrategy customStrategy, boolean addAsFirst)
Adds an search strategy to the list of proxy searches strategies.- Parameters:
customStrategy- the custom search strategy to add.addAsFirst-true: add the custom strategy as first strategy,falseappend as last strategy
-
removeStrategy
public void removeStrategy(ProxySearch.Strategy strategy)
Removes a search strategy from the list of proxy searches strategies.- Parameters:
strategy- the search strategy to remove.
-
setPacCacheSettings
public void setPacCacheSettings(int size, long ttl, BufferedProxySelector.CacheScope cacheScope)Sets the cache size of the PAC proxy selector cache. This defines the number of URLs that are cached together with the PAC script result. This improves performance because for URLs that are in the cache the script is not executed again. You have to set this before you add any strategies that may create a PAC script proxy selector.- Parameters:
size- of the cache. Set it to 0 to disable caching.ttl- is the time to live of the cache entries as amount of milliseconds.cacheScope- the desired cache scope.
-
getProxySelector
public ProxySelector getProxySelector()
Gets the proxy selector that will use the configured search order.- Specified by:
getProxySelectorin interfaceProxySearchStrategy- Returns:
- a ProxySelector, null if none was found for the current builder configuration.
-
getName
public String getName()
Gets the printable name of the search strategy.- Specified by:
getNamein interfaceProxySearchStrategy- Returns:
- the printable name of the search strategy
-
toString
public String toString()
toString- Overrides:
toStringin classObject- See Also:
Object.toString()
-
main
public static void main(String[] args)
For testing only. Will print the logging & proxy information to the console.- Parameters:
args- the command line arguments.
-
-