211 lines
5.9 KiB
Java
211 lines
5.9 KiB
Java
|
package okhttp3.repackaged;
|
||
|
|
||
|
import java.util.ArrayDeque;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collections;
|
||
|
import java.util.Deque;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
import java.util.concurrent.ExecutorService;
|
||
|
import java.util.concurrent.SynchronousQueue;
|
||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
import okhttp3.repackaged.a;
|
||
|
import okhttp3.repackaged.internal.Util;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public final class Dispatcher {
|
||
|
private ExecutorService ahx;
|
||
|
private int ahv = 64;
|
||
|
private int ahw = 5;
|
||
|
private final Deque<a.b> ahy = new ArrayDeque();
|
||
|
private final Deque<a.b> ahz = new ArrayDeque();
|
||
|
private final Deque<a> ahA = new ArrayDeque();
|
||
|
|
||
|
public Dispatcher(ExecutorService executorService) {
|
||
|
this.ahx = executorService;
|
||
|
}
|
||
|
|
||
|
public Dispatcher() {
|
||
|
}
|
||
|
|
||
|
public final ExecutorService executorService() {
|
||
|
ExecutorService executorService;
|
||
|
synchronized (this) {
|
||
|
if (this.ahx == null) {
|
||
|
this.ahx = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp Dispatcher", false));
|
||
|
}
|
||
|
executorService = this.ahx;
|
||
|
}
|
||
|
return executorService;
|
||
|
}
|
||
|
|
||
|
public final void setMaxRequests(int i) {
|
||
|
synchronized (this) {
|
||
|
if (i <= 0) {
|
||
|
StringBuilder sb = new StringBuilder("max < 1: ");
|
||
|
sb.append(i);
|
||
|
throw new IllegalArgumentException(sb.toString());
|
||
|
}
|
||
|
this.ahv = i;
|
||
|
un();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final int getMaxRequests() {
|
||
|
int i;
|
||
|
synchronized (this) {
|
||
|
i = this.ahv;
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
public final void setMaxRequestsPerHost(int i) {
|
||
|
synchronized (this) {
|
||
|
if (i <= 0) {
|
||
|
StringBuilder sb = new StringBuilder("max < 1: ");
|
||
|
sb.append(i);
|
||
|
throw new IllegalArgumentException(sb.toString());
|
||
|
}
|
||
|
this.ahw = i;
|
||
|
un();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final int getMaxRequestsPerHost() {
|
||
|
int i;
|
||
|
synchronized (this) {
|
||
|
i = this.ahw;
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void a(a.b bVar) {
|
||
|
synchronized (this) {
|
||
|
if (this.ahz.size() < this.ahv && c(bVar) < this.ahw) {
|
||
|
this.ahz.add(bVar);
|
||
|
executorService().execute(bVar);
|
||
|
} else {
|
||
|
this.ahy.add(bVar);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final void cancelAll() {
|
||
|
synchronized (this) {
|
||
|
Iterator<a.b> it = this.ahy.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
it.next().cancel();
|
||
|
}
|
||
|
Iterator<a.b> it2 = this.ahz.iterator();
|
||
|
while (it2.hasNext()) {
|
||
|
it2.next().cancel();
|
||
|
}
|
||
|
Iterator<a> it3 = this.ahA.iterator();
|
||
|
while (it3.hasNext()) {
|
||
|
it3.next().cancel();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void b(a.b bVar) {
|
||
|
synchronized (this) {
|
||
|
if (!this.ahz.remove(bVar)) {
|
||
|
throw new AssertionError("AsyncCall wasn't running!");
|
||
|
}
|
||
|
un();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void un() {
|
||
|
if (this.ahz.size() < this.ahv && !this.ahy.isEmpty()) {
|
||
|
Iterator<a.b> it = this.ahy.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
a.b next = it.next();
|
||
|
if (c(next) < this.ahw) {
|
||
|
it.remove();
|
||
|
this.ahz.add(next);
|
||
|
executorService().execute(next);
|
||
|
}
|
||
|
if (this.ahz.size() >= this.ahv) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private int c(a.b bVar) {
|
||
|
Iterator<a.b> it = this.ahz.iterator();
|
||
|
int i = 0;
|
||
|
while (it.hasNext()) {
|
||
|
if (it.next().host().equals(bVar.host())) {
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void a(a aVar) {
|
||
|
synchronized (this) {
|
||
|
this.ahA.add(aVar);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final void a(Call call) {
|
||
|
synchronized (this) {
|
||
|
if (!this.ahA.remove(call)) {
|
||
|
throw new AssertionError("Call wasn't in-flight!");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final List<Call> queuedCalls() {
|
||
|
List<Call> unmodifiableList;
|
||
|
synchronized (this) {
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
Iterator<a.b> it = this.ahy.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
arrayList.add(it.next().us());
|
||
|
}
|
||
|
unmodifiableList = Collections.unmodifiableList(arrayList);
|
||
|
}
|
||
|
return unmodifiableList;
|
||
|
}
|
||
|
|
||
|
public final List<Call> runningCalls() {
|
||
|
List<Call> unmodifiableList;
|
||
|
synchronized (this) {
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
arrayList.addAll(this.ahA);
|
||
|
Iterator<a.b> it = this.ahz.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
arrayList.add(it.next().us());
|
||
|
}
|
||
|
unmodifiableList = Collections.unmodifiableList(arrayList);
|
||
|
}
|
||
|
return unmodifiableList;
|
||
|
}
|
||
|
|
||
|
public final int queuedCallsCount() {
|
||
|
int size;
|
||
|
synchronized (this) {
|
||
|
size = this.ahy.size();
|
||
|
}
|
||
|
return size;
|
||
|
}
|
||
|
|
||
|
public final int runningCallsCount() {
|
||
|
int size;
|
||
|
int size2;
|
||
|
synchronized (this) {
|
||
|
size = this.ahz.size();
|
||
|
size2 = this.ahA.size();
|
||
|
}
|
||
|
return size + size2;
|
||
|
}
|
||
|
}
|