org.browsermob.proxy.ProxyManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of browsermob-proxy Show documentation
Show all versions of browsermob-proxy Show documentation
A programmatic HTTP/S designed for performance and functional testing
The newest version!
package org.browsermob.proxy;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.Provider;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@Singleton
public class ProxyManager {
private AtomicInteger portCounter = new AtomicInteger(9090);
private Provider proxyServerProvider;
private Map proxies = new ConcurrentHashMap();
@Inject
public ProxyManager(Provider proxyServerProvider) {
this.proxyServerProvider = proxyServerProvider;
}
public ProxyServer create(Map options, int port) throws Exception {
ProxyServer proxy = proxyServerProvider.get();
proxy.setPort(port);
proxy.start();
proxy.setOptions(options);
proxies.put(port, proxy);
return proxy;
}
public ProxyServer create(Map options) throws Exception {
int port = portCounter.incrementAndGet();
ProxyServer proxy = proxyServerProvider.get();
proxy.setPort(port);
proxy.start();
proxy.setOptions(options);
proxies.put(port, proxy);
return proxy;
}
public ProxyServer get(int port) {
return proxies.get(port);
}
public void delete(int port) throws Exception {
ProxyServer proxy = proxies.remove(port);
proxy.stop();
}
}