All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webpieces.httpproxy.impl.HttpProxyModule Maven / Gradle / Ivy

Go to download

Someone forgot to fill this in. See http://stackoverflow.com/questions/38272550/how-to-fail-the-gradle-build-if-subproject-is-missing-a-property

The newest version!
package org.webpieces.httpproxy.impl;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import javax.inject.Singleton;

import org.webpieces.data.api.BufferCreationPool;
import org.webpieces.frontend.api.HttpFrontendFactory;
import org.webpieces.frontend.api.HttpFrontendManager;
import org.webpieces.httpclient.api.HttpClient;
import org.webpieces.httpclient.api.HttpClientFactory;
import org.webpieces.httpproxy.api.HttpProxy;
import org.webpieces.httpproxy.api.ProxyConfig;
import org.webpieces.util.threading.NamedThreadFactory;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;

public class HttpProxyModule implements Module {

	private ProxyConfig config;

	public HttpProxyModule(ProxyConfig config) {
		this.config = config;
	}
	@Override
	public void configure(Binder binder) {
		binder.bind(HttpProxy.class).to(HttpProxyImpl.class);

		binder.bind(ProxyConfig.class).toInstance(config);
	}

	@Provides
	@Singleton
	public ScheduledExecutorService provideTimer() {
		return new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("webpieces-timer"));
	}
	
	@Provides
	@Singleton
	public HttpFrontendManager providesAsyncServerMgr(ProxyConfig config, ScheduledExecutorService timer) {
		BufferCreationPool pool = new BufferCreationPool();
		return HttpFrontendFactory.createFrontEnd("httpFrontEnd", config.getNumFrontendServerThreads(), timer, pool);
	}
	
	@Provides
	@Singleton
	public HttpClient provideHttpClient(ProxyConfig config) {
		if(config.isForceAllConnectionToHttps())
			return HttpClientFactory.createHttpsClient(config.getNumHttpClientThreads(), new ForTestSslClientEngineFactory());
		
		return HttpClientFactory.createHttpClient(config.getNumHttpClientThreads());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy