AbstractScheduledService.java
15 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package com.google.common.util.concurrent;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
@Beta
public abstract class AbstractScheduledService
implements Service
{
private static final Logger a = Logger.getLogger(AbstractScheduledService.class.getName());
private final AbstractService b = new AbstractService()
{
private volatile Future<?> b;
private volatile ScheduledExecutorService c;
private final ReentrantLock d = new ReentrantLock();
private final Runnable e = new Runnable()
{
/* Error */
public final void run()
{
// Byte code:
// 0: aload_0
// 1: getfield 14 com/google/common/util/concurrent/AbstractScheduledService$1$1:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 4: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 7: invokevirtual 31 java/util/concurrent/locks/ReentrantLock:lock ()V
// 10: aload_0
// 11: getfield 14 com/google/common/util/concurrent/AbstractScheduledService$1$1:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 14: getfield 34 com/google/common/util/concurrent/AbstractScheduledService$1:a Lcom/google/common/util/concurrent/AbstractScheduledService;
// 17: invokevirtual 39 com/google/common/util/concurrent/AbstractScheduledService:runOneIteration ()V
// 20: aload_0
// 21: getfield 14 com/google/common/util/concurrent/AbstractScheduledService$1$1:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 24: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 27: invokevirtual 42 java/util/concurrent/locks/ReentrantLock:unlock ()V
// 30: return
// 31: astore_1
// 32: aload_0
// 33: getfield 14 com/google/common/util/concurrent/AbstractScheduledService$1$1:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 36: getfield 34 com/google/common/util/concurrent/AbstractScheduledService$1:a Lcom/google/common/util/concurrent/AbstractScheduledService;
// 39: invokevirtual 45 com/google/common/util/concurrent/AbstractScheduledService:shutDown ()V
// 42: aload_0
// 43: getfield 14 com/google/common/util/concurrent/AbstractScheduledService$1$1:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 46: aload_1
// 47: invokevirtual 49 com/google/common/util/concurrent/AbstractScheduledService$1:notifyFailed (Ljava/lang/Throwable;)V
// 50: aload_1
// 51: invokestatic 55 com/google/common/base/Throwables:propagate (Ljava/lang/Throwable;)Ljava/lang/RuntimeException;
// 54: athrow
// 55: astore_1
// 56: aload_0
// 57: getfield 14 com/google/common/util/concurrent/AbstractScheduledService$1$1:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 60: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 63: invokevirtual 42 java/util/concurrent/locks/ReentrantLock:unlock ()V
// 66: aload_1
// 67: athrow
// 68: astore_2
// 69: invokestatic 58 com/google/common/util/concurrent/AbstractScheduledService:a ()Ljava/util/logging/Logger;
// 72: getstatic 64 java/util/logging/Level:WARNING Ljava/util/logging/Level;
// 75: ldc 66
// 77: aload_2
// 78: invokevirtual 72 java/util/logging/Logger:log (Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Throwable;)V
// 81: goto -39 -> 42
// Local variable table:
// start length slot name signature
// 0 84 0 this 1
// 31 20 1 localThrowable Throwable
// 55 12 1 localObject Object
// 68 10 2 localException Exception
// Exception table:
// from to target type
// 10 20 31 java/lang/Throwable
// 10 20 55 finally
// 32 42 55 finally
// 42 55 55 finally
// 69 81 55 finally
// 32 42 68 java/lang/Exception
}
};
protected final void doStart()
{
this.c = MoreExecutors.a(AbstractScheduledService.this.executor(), new Supplier() {});
this.c.execute(new Runnable()
{
public final void run()
{
AbstractScheduledService.1.a(AbstractScheduledService.1.this).lock();
try
{
AbstractScheduledService.this.startUp();
AbstractScheduledService.1 local1 = AbstractScheduledService.1.this;
AbstractScheduledService.Scheduler localScheduler = AbstractScheduledService.this.scheduler();
AbstractScheduledService.a(AbstractScheduledService.this);
AbstractScheduledService.1.a(local1, localScheduler.a(AbstractScheduledService.1.b(AbstractScheduledService.1.this), AbstractScheduledService.1.c(AbstractScheduledService.1.this)));
AbstractScheduledService.1.this.notifyStarted();
return;
}
catch (Throwable localThrowable)
{
AbstractScheduledService.1.this.notifyFailed(localThrowable);
throw Throwables.propagate(localThrowable);
}
finally
{
AbstractScheduledService.1.a(AbstractScheduledService.1.this).unlock();
}
}
});
}
protected final void doStop()
{
this.b.cancel(false);
this.c.execute(new Runnable()
{
/* Error */
public final void run()
{
// Byte code:
// 0: aload_0
// 1: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 4: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 7: invokevirtual 31 java/util/concurrent/locks/ReentrantLock:lock ()V
// 10: aload_0
// 11: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 14: invokevirtual 35 com/google/common/util/concurrent/AbstractScheduledService$1:state ()Lcom/google/common/util/concurrent/Service$State;
// 17: astore_1
// 18: getstatic 41 com/google/common/util/concurrent/Service$State:STOPPING Lcom/google/common/util/concurrent/Service$State;
// 21: astore_2
// 22: aload_1
// 23: aload_2
// 24: if_acmpeq +14 -> 38
// 27: aload_0
// 28: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 31: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 34: invokevirtual 44 java/util/concurrent/locks/ReentrantLock:unlock ()V
// 37: return
// 38: aload_0
// 39: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 42: getfield 47 com/google/common/util/concurrent/AbstractScheduledService$1:a Lcom/google/common/util/concurrent/AbstractScheduledService;
// 45: invokevirtual 52 com/google/common/util/concurrent/AbstractScheduledService:shutDown ()V
// 48: aload_0
// 49: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 52: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 55: invokevirtual 44 java/util/concurrent/locks/ReentrantLock:unlock ()V
// 58: aload_0
// 59: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 62: invokevirtual 55 com/google/common/util/concurrent/AbstractScheduledService$1:notifyStopped ()V
// 65: return
// 66: astore_1
// 67: aload_0
// 68: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 71: aload_1
// 72: invokevirtual 59 com/google/common/util/concurrent/AbstractScheduledService$1:notifyFailed (Ljava/lang/Throwable;)V
// 75: aload_1
// 76: invokestatic 65 com/google/common/base/Throwables:propagate (Ljava/lang/Throwable;)Ljava/lang/RuntimeException;
// 79: athrow
// 80: astore_1
// 81: aload_0
// 82: getfield 17 com/google/common/util/concurrent/AbstractScheduledService$1$4:a Lcom/google/common/util/concurrent/AbstractScheduledService$1;
// 85: invokestatic 26 com/google/common/util/concurrent/AbstractScheduledService$1:a (Lcom/google/common/util/concurrent/AbstractScheduledService$1;)Ljava/util/concurrent/locks/ReentrantLock;
// 88: invokevirtual 44 java/util/concurrent/locks/ReentrantLock:unlock ()V
// 91: aload_1
// 92: athrow
// Local variable table:
// start length slot name signature
// 0 93 0 this 4
// 17 6 1 localState1 Service.State
// 66 10 1 localThrowable Throwable
// 80 12 1 localObject Object
// 21 3 2 localState2 Service.State
// Exception table:
// from to target type
// 0 10 66 java/lang/Throwable
// 27 37 66 java/lang/Throwable
// 48 65 66 java/lang/Throwable
// 81 93 66 java/lang/Throwable
// 10 22 80 finally
// 38 48 80 finally
}
});
}
};
public final void addListener(Service.Listener paramListener, Executor paramExecutor)
{
this.b.addListener(paramListener, paramExecutor);
}
public final void awaitRunning()
{
this.b.awaitRunning();
}
public final void awaitRunning(long paramLong, TimeUnit paramTimeUnit)
throws TimeoutException
{
this.b.awaitRunning(paramLong, paramTimeUnit);
}
public final void awaitTerminated()
{
this.b.awaitTerminated();
}
public final void awaitTerminated(long paramLong, TimeUnit paramTimeUnit)
throws TimeoutException
{
this.b.awaitTerminated(paramLong, paramTimeUnit);
}
protected ScheduledExecutorService executor()
{
final ScheduledExecutorService localScheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory()
{
public final Thread newThread(Runnable paramAnonymousRunnable)
{
return MoreExecutors.a(AbstractScheduledService.this.serviceName(), paramAnonymousRunnable);
}
});
addListener(new Service.Listener()
{
public final void failed(Service.State paramAnonymousState, Throwable paramAnonymousThrowable)
{
localScheduledExecutorService.shutdown();
}
public final void terminated(Service.State paramAnonymousState)
{
localScheduledExecutorService.shutdown();
}
}, MoreExecutors.directExecutor());
return localScheduledExecutorService;
}
public final Throwable failureCause()
{
return this.b.failureCause();
}
public final boolean isRunning()
{
return this.b.isRunning();
}
protected abstract void runOneIteration()
throws Exception;
protected abstract Scheduler scheduler();
protected String serviceName()
{
return getClass().getSimpleName();
}
protected void shutDown()
throws Exception
{}
public final Service startAsync()
{
this.b.startAsync();
return this;
}
protected void startUp()
throws Exception
{}
public final Service.State state()
{
return this.b.state();
}
public final Service stopAsync()
{
this.b.stopAsync();
return this;
}
public String toString()
{
String str1 = String.valueOf(String.valueOf(serviceName()));
String str2 = String.valueOf(String.valueOf(state()));
return str1.length() + 3 + str2.length() + str1 + " [" + str2 + "]";
}
@Beta
public static abstract class CustomScheduler
extends AbstractScheduledService.Scheduler
{
public CustomScheduler()
{
super();
}
protected abstract Schedule getNextSchedule()
throws Exception;
@Beta
public static final class Schedule
{
private final long a;
private final TimeUnit b;
public Schedule(long paramLong, TimeUnit paramTimeUnit)
{
this.a = paramLong;
this.b = ((TimeUnit)Preconditions.checkNotNull(paramTimeUnit));
}
}
}
public static abstract class Scheduler
{
public static Scheduler newFixedDelaySchedule(long paramLong1, long paramLong2, final TimeUnit paramTimeUnit)
{
new Scheduler(paramLong1)
{
public final Future<?> a(ScheduledExecutorService paramAnonymousScheduledExecutorService, Runnable paramAnonymousRunnable)
{
return paramAnonymousScheduledExecutorService.scheduleWithFixedDelay(paramAnonymousRunnable, this.a, paramTimeUnit, this.c);
}
};
}
public static Scheduler newFixedRateSchedule(long paramLong1, long paramLong2, final TimeUnit paramTimeUnit)
{
new Scheduler(paramLong1)
{
public final Future<?> a(ScheduledExecutorService paramAnonymousScheduledExecutorService, Runnable paramAnonymousRunnable)
{
return paramAnonymousScheduledExecutorService.scheduleAtFixedRate(paramAnonymousRunnable, this.a, paramTimeUnit, this.c);
}
};
}
abstract Future<?> a(ScheduledExecutorService paramScheduledExecutorService, Runnable paramRunnable);
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/util/concurrent/AbstractScheduledService.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/