io.femo.http.drivers.AsynchronousDriver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-jdk7 Show documentation
Show all versions of http-jdk7 Show documentation
An easy to use HTTP API, that supports synchronous and asynchronous execution of HTTP request.
On android only asynchronous driver is supported.
This library has been backported to jdk 7 to retain compatibility with android!
The newest version!
package io.femo.http.drivers;
import io.femo.http.HttpDriver;
import io.femo.http.HttpRequest;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by felix on 2/9/16.
*/
public class AsynchronousDriver extends DefaultDriver {
private ExecutorService executorService;
public AsynchronousDriver() {
executorService = null;
}
public AsynchronousDriver(int threads) {
this.executorService = Executors.newFixedThreadPool(threads);
}
@Override
public HttpRequest url(URL url) {
if(executorService == null)
return new AsynchronousHttpRequest(url);
return new AsynchronousExecutorHttpRequest(url, executorService);
}
}