Connection.java
5.34 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
package com.squareup.okhttp.internal.allocations;
import com.squareup.okhttp.ConnectionPool;
import com.squareup.okhttp.internal.Internal;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
public final class Connection
{
private int allocationLimit = 1;
private final List<StreamAllocationReference> allocations = new ArrayList();
long idleAt = Long.MAX_VALUE;
private boolean noNewAllocations;
private final ConnectionPool pool;
public Connection(ConnectionPool paramConnectionPool)
{
this.pool = paramConnectionPool;
}
private void remove(StreamAllocation paramStreamAllocation)
{
int j = this.allocations.size();
int i = 0;
while (i < j)
{
if (((StreamAllocationReference)this.allocations.get(i)).get() == paramStreamAllocation)
{
this.allocations.remove(i);
if (this.allocations.isEmpty()) {
this.idleAt = System.nanoTime();
}
return;
}
i += 1;
}
throw new IllegalArgumentException("unexpected allocation: " + paramStreamAllocation);
}
public final void noNewStreams()
{
synchronized (this.pool)
{
this.noNewAllocations = true;
int i = 0;
while (i < this.allocations.size())
{
((StreamAllocationReference)this.allocations.get(i)).rescind();
i += 1;
}
return;
}
}
public final void pruneLeakedAllocations()
{
synchronized (this.pool)
{
Iterator localIterator = this.allocations.iterator();
while (localIterator.hasNext())
{
StreamAllocationReference localStreamAllocationReference = (StreamAllocationReference)localIterator.next();
if (localStreamAllocationReference.get() == null)
{
Internal.logger.warning("Call " + localStreamAllocationReference.name + " leaked a connection. Did you forget to close a response body?");
this.noNewAllocations = true;
localIterator.remove();
if (this.allocations.isEmpty()) {
this.idleAt = System.nanoTime();
}
}
}
}
}
public final void release(StreamAllocation paramStreamAllocation)
{
synchronized (this.pool)
{
if (paramStreamAllocation.released) {
throw new IllegalStateException("already released");
}
}
StreamAllocation.access$102(paramStreamAllocation, true);
if (paramStreamAllocation.stream == null) {
remove(paramStreamAllocation);
}
}
public final StreamAllocation reserve(String paramString)
{
synchronized (this.pool)
{
if ((this.noNewAllocations) || (this.allocations.size() >= this.allocationLimit)) {
return null;
}
StreamAllocation localStreamAllocation = new StreamAllocation(null);
this.allocations.add(new StreamAllocationReference(localStreamAllocation, paramString));
return localStreamAllocation;
}
}
public final void setAllocationLimit(int paramInt)
{
ConnectionPool localConnectionPool = this.pool;
if (paramInt < 0) {
try
{
throw new IllegalArgumentException();
}
finally {}
}
this.allocationLimit = paramInt;
while (paramInt < this.allocations.size())
{
((StreamAllocationReference)this.allocations.get(paramInt)).rescind();
paramInt += 1;
}
}
final int size()
{
synchronized (this.pool)
{
int i = this.allocations.size();
return i;
}
}
public static class Stream
{
public final String name;
public Stream(String paramString)
{
this.name = paramString;
}
public String toString()
{
return this.name;
}
}
public final class StreamAllocation
{
private boolean released;
private boolean rescinded;
private Connection.Stream stream;
private StreamAllocation() {}
public final Connection.Stream newStream(String paramString)
{
synchronized (Connection.this.pool)
{
if ((this.stream != null) || (this.released)) {
throw new IllegalStateException();
}
}
return paramString;
}
public final void streamComplete(Connection.Stream paramStream)
{
ConnectionPool localConnectionPool = Connection.this.pool;
if (paramStream != null) {}
try
{
if (paramStream != this.stream) {
throw new IllegalArgumentException();
}
}
finally
{
throw paramStream;
this.stream = null;
if (!this.released) {}
}
}
}
static final class StreamAllocationReference
extends WeakReference<Connection.StreamAllocation>
{
private final String name;
public StreamAllocationReference(Connection.StreamAllocation paramStreamAllocation, String paramString)
{
super();
this.name = paramString;
}
public final void rescind()
{
Connection.StreamAllocation localStreamAllocation = (Connection.StreamAllocation)get();
if (localStreamAllocation != null) {
Connection.StreamAllocation.access$602(localStreamAllocation, true);
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/allocations/Connection.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/