diff --git a/okhttp/src/main/java/com/squareup/okhttp/Dispatcher.java b/okhttp/src/main/java/com/squareup/okhttp/Dispatcher.java
index 198fd4ea80d9..58e06be40bce 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/Dispatcher.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/Dispatcher.java
@@ -19,7 +19,7 @@
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
-import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -27,7 +27,7 @@
/**
* Policy on when async requests are executed.
*
- * Each dispatcher uses an {@link Executor} to run jobs internally. If you
+ *
Each dispatcher uses an {@link ExecutorService} to run jobs internally. If you
* supply your own executor, it should be able to run {@link #getMaxRequests the
* configured maximum} number of jobs concurrently.
*/
@@ -36,7 +36,7 @@ public final class Dispatcher {
private int maxRequestsPerHost = 5;
/** Executes jobs. Created lazily. */
- private Executor executor;
+ private ExecutorService executorService;
/** Ready jobs in the order they'll be run. */
private final Deque readyJobs = new ArrayDeque();
@@ -44,19 +44,19 @@ public final class Dispatcher {
/** Running jobs. Includes canceled jobs that haven't finished yet. */
private final Deque runningJobs = new ArrayDeque();
- public Dispatcher(Executor executor) {
- this.executor = executor;
+ public Dispatcher(ExecutorService executorService) {
+ this.executorService = executorService;
}
public Dispatcher() {
}
- public synchronized Executor getExecutor() {
- if (executor == null) {
- executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS,
+ public synchronized ExecutorService getExecutorService() {
+ if (executorService == null) {
+ executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS,
new LinkedBlockingQueue(), Util.threadFactory("OkHttp Dispatcher", false));
}
- return executor;
+ return executorService;
}
/**
@@ -107,7 +107,7 @@ synchronized void enqueue(OkHttpClient client, Request request, Response.Receive
if (runningJobs.size() < maxRequests && runningJobsForHost(job) < maxRequestsPerHost) {
runningJobs.add(job);
- getExecutor().execute(job);
+ getExecutorService().execute(job);
} else {
readyJobs.add(job);
}
@@ -143,7 +143,7 @@ private void promoteJobs() {
if (runningJobsForHost(job) < maxRequestsPerHost) {
i.remove();
runningJobs.add(job);
- getExecutor().execute(job);
+ getExecutorService().execute(job);
}
if (runningJobs.size() >= maxRequests) return; // Reached max capacity.
diff --git a/okhttp/src/test/java/com/squareup/okhttp/DispatcherTest.java b/okhttp/src/test/java/com/squareup/okhttp/DispatcherTest.java
index 034ed84b6465..a42362fbff44 100644
--- a/okhttp/src/test/java/com/squareup/okhttp/DispatcherTest.java
+++ b/okhttp/src/test/java/com/squareup/okhttp/DispatcherTest.java
@@ -4,7 +4,8 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import java.util.concurrent.Executor;
+import java.util.concurrent.AbstractExecutorService;
+import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -129,7 +130,7 @@ public final class DispatcherTest {
executor.assertJobs("http://a/2");
}
- class RecordingExecutor implements Executor {
+ class RecordingExecutor extends AbstractExecutorService {
private List jobs = new ArrayList();
@Override public void execute(Runnable command) {
@@ -155,6 +156,27 @@ public void finishJob(String url) {
}
throw new AssertionError("No such job: " + url);
}
+
+ @Override public void shutdown() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override public List shutdownNow() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override public boolean isShutdown() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override public boolean isTerminated() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override public boolean awaitTermination(long timeout, TimeUnit unit)
+ throws InterruptedException {
+ throw new UnsupportedOperationException();
+ }
}
private Request newRequest(String url) {
diff --git a/pom.xml b/pom.xml
index aea71da07add..82861f385904 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,6 +22,7 @@
okhttp
okhttp-apache
okhttp-protocols
+ okcurl
mockwebserver
samples
benchmarks
@@ -36,6 +37,8 @@
1.48
2.2.3
4.2.2
+ 0.6
+ 16.0
4.11
@@ -87,6 +90,16 @@
httpclient
${apache.http.version}
+
+ io.airlift
+ airline
+ ${airlift.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+