SimpleTimeLimiter.java
5.44 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
package com.google.common.util.concurrent;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.collect.ObjectArrays;
import com.google.common.collect.Sets;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@Beta
public final class SimpleTimeLimiter
implements TimeLimiter
{
private final ExecutorService a;
public SimpleTimeLimiter()
{
this(Executors.newCachedThreadPool());
}
public SimpleTimeLimiter(ExecutorService paramExecutorService)
{
this.a = ((ExecutorService)Preconditions.checkNotNull(paramExecutorService));
}
private static Exception a(Exception paramException, boolean paramBoolean)
throws Exception
{
Throwable localThrowable = paramException.getCause();
if (localThrowable == null) {
throw paramException;
}
if (paramBoolean) {
localThrowable.setStackTrace((StackTraceElement[])ObjectArrays.concat(localThrowable.getStackTrace(), paramException.getStackTrace(), StackTraceElement.class));
}
if ((localThrowable instanceof Exception)) {
throw ((Exception)localThrowable);
}
if ((localThrowable instanceof Error)) {
throw ((Error)localThrowable);
}
throw paramException;
}
public final <T> T callWithTimeout(Callable<T> paramCallable, long paramLong, TimeUnit paramTimeUnit, boolean paramBoolean)
throws Exception
{
Preconditions.checkNotNull(paramCallable);
Preconditions.checkNotNull(paramTimeUnit);
if (paramLong > 0L) {}
for (boolean bool = true;; bool = false)
{
Preconditions.checkArgument(bool, "timeout must be positive: %s", new Object[] { Long.valueOf(paramLong) });
paramCallable = this.a.submit(paramCallable);
if (!paramBoolean) {
break;
}
try
{
paramTimeUnit = paramCallable.get(paramLong, paramTimeUnit);
return paramTimeUnit;
}
catch (InterruptedException paramTimeUnit)
{
paramCallable.cancel(true);
throw paramTimeUnit;
}
catch (ExecutionException paramCallable)
{
throw a(paramCallable, true);
paramTimeUnit = Uninterruptibles.getUninterruptibly(paramCallable, paramLong, paramTimeUnit);
return paramTimeUnit;
}
catch (TimeoutException paramTimeUnit)
{
paramCallable.cancel(true);
throw new UncheckedTimeoutException(paramTimeUnit);
}
}
}
public final <T> T newProxy(final T paramT, Class<T> paramClass, final long paramLong, TimeUnit paramTimeUnit)
{
Preconditions.checkNotNull(paramT);
Preconditions.checkNotNull(paramClass);
Preconditions.checkNotNull(paramTimeUnit);
boolean bool;
final HashSet localHashSet;
int i;
label71:
Method localMethod;
if (paramLong > 0L)
{
bool = true;
Preconditions.checkArgument(bool, "bad timeout: %s", new Object[] { Long.valueOf(paramLong) });
Preconditions.checkArgument(paramClass.isInterface(), "interfaceType must be an interface type");
localHashSet = Sets.newHashSet();
Method[] arrayOfMethod = paramClass.getMethods();
int k = arrayOfMethod.length;
i = 0;
if (i >= k) {
break label165;
}
localMethod = arrayOfMethod[i];
Class[] arrayOfClass = localMethod.getExceptionTypes();
int m = arrayOfClass.length;
j = 0;
label100:
if (j >= m) {
break label159;
}
if (arrayOfClass[j] != InterruptedException.class) {
break label150;
}
}
label150:
label159:
for (int j = 1;; j = 0)
{
if (j != 0) {
localHashSet.add(localMethod);
}
i += 1;
break label71;
bool = false;
break;
j += 1;
break label100;
}
label165:
paramT = new InvocationHandler()
{
public final Object invoke(Object paramAnonymousObject, final Method paramAnonymousMethod, final Object[] paramAnonymousArrayOfObject)
throws Throwable
{
paramAnonymousObject = new Callable()
{
public final Object call()
throws Exception
{
try
{
Object localObject = paramAnonymousMethod.invoke(SimpleTimeLimiter.1.this.a, paramAnonymousArrayOfObject);
return localObject;
}
catch (InvocationTargetException localInvocationTargetException)
{
SimpleTimeLimiter.a(localInvocationTargetException);
throw new AssertionError("can't get here");
}
}
};
return SimpleTimeLimiter.this.callWithTimeout((Callable)paramAnonymousObject, paramLong, localHashSet, this.d.contains(paramAnonymousMethod));
}
};
return (T)paramClass.cast(Proxy.newProxyInstance(paramClass.getClassLoader(), new Class[] { paramClass }, paramT));
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/util/concurrent/SimpleTimeLimiter.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/