Dispatcher.java
7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package com.squareup.okhttp;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.http.HttpEngine;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public final class Dispatcher
{
private final Deque<Call> executedCalls = new ArrayDeque();
private ExecutorService executorService;
private int maxRequests = 64;
private int maxRequestsPerHost = 5;
private final Deque<Call.AsyncCall> readyCalls = new ArrayDeque();
private final Deque<Call.AsyncCall> runningCalls = new ArrayDeque();
public Dispatcher() {}
public Dispatcher(ExecutorService paramExecutorService)
{
this.executorService = paramExecutorService;
}
private void promoteCalls()
{
if (this.runningCalls.size() >= this.maxRequests) {}
do
{
Iterator localIterator;
do
{
return;
while (this.readyCalls.isEmpty()) {}
localIterator = this.readyCalls.iterator();
} while (!localIterator.hasNext());
Call.AsyncCall localAsyncCall = (Call.AsyncCall)localIterator.next();
if (runningCallsForHost(localAsyncCall) < this.maxRequestsPerHost)
{
localIterator.remove();
this.runningCalls.add(localAsyncCall);
getExecutorService().execute(localAsyncCall);
}
} while (this.runningCalls.size() < this.maxRequests);
}
private int runningCallsForHost(Call.AsyncCall paramAsyncCall)
{
Iterator localIterator = this.runningCalls.iterator();
int i = 0;
if (localIterator.hasNext())
{
if (!((Call.AsyncCall)localIterator.next()).host().equals(paramAsyncCall.host())) {
break label52;
}
i += 1;
}
label52:
for (;;)
{
break;
return i;
}
}
public final void cancel(Object paramObject)
{
Object localObject;
try
{
localIterator = this.readyCalls.iterator();
while (localIterator.hasNext())
{
localObject = (Call.AsyncCall)localIterator.next();
if (Util.equal(paramObject, ((Call.AsyncCall)localObject).tag())) {
((Call.AsyncCall)localObject).cancel();
}
}
localIterator = this.runningCalls.iterator();
}
finally {}
while (localIterator.hasNext())
{
localObject = (Call.AsyncCall)localIterator.next();
if (Util.equal(paramObject, ((Call.AsyncCall)localObject).tag()))
{
((Call.AsyncCall)localObject).get().canceled = true;
localObject = ((Call.AsyncCall)localObject).get().engine;
if (localObject != null) {
((HttpEngine)localObject).disconnect();
}
}
}
Iterator localIterator = this.executedCalls.iterator();
while (localIterator.hasNext())
{
localObject = (Call)localIterator.next();
if (Util.equal(paramObject, ((Call)localObject).tag())) {
((Call)localObject).cancel();
}
}
}
/* Error */
final void enqueue(Call.AsyncCall paramAsyncCall)
{
// Byte code:
// 0: aload_0
// 1: monitorenter
// 2: aload_0
// 3: getfield 30 com/squareup/okhttp/Dispatcher:runningCalls Ljava/util/Deque;
// 6: invokeinterface 43 1 0
// 11: aload_0
// 12: getfield 21 com/squareup/okhttp/Dispatcher:maxRequests I
// 15: if_icmpge +39 -> 54
// 18: aload_0
// 19: aload_1
// 20: invokespecial 66 com/squareup/okhttp/Dispatcher:runningCallsForHost (Lcom/squareup/okhttp/Call$AsyncCall;)I
// 23: aload_0
// 24: getfield 23 com/squareup/okhttp/Dispatcher:maxRequestsPerHost I
// 27: if_icmpge +27 -> 54
// 30: aload_0
// 31: getfield 30 com/squareup/okhttp/Dispatcher:runningCalls Ljava/util/Deque;
// 34: aload_1
// 35: invokeinterface 73 2 0
// 40: pop
// 41: aload_0
// 42: invokevirtual 77 com/squareup/okhttp/Dispatcher:getExecutorService ()Ljava/util/concurrent/ExecutorService;
// 45: aload_1
// 46: invokeinterface 83 2 0
// 51: aload_0
// 52: monitorexit
// 53: return
// 54: aload_0
// 55: getfield 28 com/squareup/okhttp/Dispatcher:readyCalls Ljava/util/Deque;
// 58: aload_1
// 59: invokeinterface 73 2 0
// 64: pop
// 65: goto -14 -> 51
// 68: astore_1
// 69: aload_0
// 70: monitorexit
// 71: aload_1
// 72: athrow
// Local variable table:
// start length slot name signature
// 0 73 0 this Dispatcher
// 0 73 1 paramAsyncCall Call.AsyncCall
// Exception table:
// from to target type
// 2 51 68 finally
// 54 65 68 finally
}
final void executed(Call paramCall)
{
try
{
this.executedCalls.add(paramCall);
return;
}
finally
{
paramCall = finally;
throw paramCall;
}
}
final void finished(Call.AsyncCall paramAsyncCall)
{
try
{
if (!this.runningCalls.remove(paramAsyncCall)) {
throw new AssertionError("AsyncCall wasn't running!");
}
}
finally {}
promoteCalls();
}
final void finished(Call paramCall)
{
try
{
if (!this.executedCalls.remove(paramCall)) {
throw new AssertionError("Call wasn't in-flight!");
}
}
finally {}
}
public final ExecutorService getExecutorService()
{
try
{
if (this.executorService == null) {
this.executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp Dispatcher", false));
}
ExecutorService localExecutorService = this.executorService;
return localExecutorService;
}
finally {}
}
public final int getMaxRequests()
{
try
{
int i = this.maxRequests;
return i;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
public final int getMaxRequestsPerHost()
{
try
{
int i = this.maxRequestsPerHost;
return i;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
public final int getQueuedCallCount()
{
try
{
int i = this.readyCalls.size();
return i;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
public final int getRunningCallCount()
{
try
{
int i = this.runningCalls.size();
return i;
}
finally
{
localObject = finally;
throw ((Throwable)localObject);
}
}
public final void setMaxRequests(int paramInt)
{
if (paramInt <= 0) {
try
{
throw new IllegalArgumentException("max < 1: " + paramInt);
}
finally {}
}
this.maxRequests = paramInt;
promoteCalls();
}
public final void setMaxRequestsPerHost(int paramInt)
{
if (paramInt <= 0) {
try
{
throw new IllegalArgumentException("max < 1: " + paramInt);
}
finally {}
}
this.maxRequestsPerHost = paramInt;
promoteCalls();
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/Dispatcher.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/