1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.shiro.concurrent; |
20 | |
|
21 | |
import java.util.concurrent.*; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class SubjectAwareScheduledExecutorService extends SubjectAwareExecutorService implements ScheduledExecutorService { |
28 | |
|
29 | |
private ScheduledExecutorService targetScheduledExecutorService; |
30 | |
|
31 | 0 | public SubjectAwareScheduledExecutorService() { |
32 | 0 | } |
33 | |
|
34 | 0 | public SubjectAwareScheduledExecutorService(ScheduledExecutorService target) { |
35 | 0 | setTargetScheduledExecutorService(target); |
36 | 0 | } |
37 | |
|
38 | |
public ScheduledExecutorService getTargetScheduledExecutorService() { |
39 | 0 | return targetScheduledExecutorService; |
40 | |
} |
41 | |
|
42 | |
public void setTargetScheduledExecutorService(ScheduledExecutorService targetScheduledExecutorService) { |
43 | 0 | super.setTargetExecutorService(targetScheduledExecutorService); |
44 | 0 | this.targetScheduledExecutorService = targetScheduledExecutorService; |
45 | 0 | } |
46 | |
|
47 | |
@Override |
48 | |
public void setTargetExecutor(Executor targetExecutor) { |
49 | 0 | if (!(targetExecutor instanceof ScheduledExecutorService)) { |
50 | 0 | String msg = "The " + getClass().getName() + " implementation only accepts " + |
51 | |
ScheduledExecutorService.class.getName() + " target instances."; |
52 | 0 | throw new IllegalArgumentException(msg); |
53 | |
} |
54 | 0 | super.setTargetExecutorService((ScheduledExecutorService) targetExecutor); |
55 | 0 | } |
56 | |
|
57 | |
@Override |
58 | |
public void setTargetExecutorService(ExecutorService targetExecutorService) { |
59 | 0 | if (!(targetExecutorService instanceof ScheduledExecutorService)) { |
60 | 0 | String msg = "The " + getClass().getName() + " implementation only accepts " + |
61 | |
ScheduledExecutorService.class.getName() + " target instances."; |
62 | 0 | throw new IllegalArgumentException(msg); |
63 | |
} |
64 | 0 | super.setTargetExecutorService(targetExecutorService); |
65 | 0 | } |
66 | |
|
67 | |
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { |
68 | 0 | Runnable work = associateWithSubject(command); |
69 | 0 | return this.targetScheduledExecutorService.schedule(work, delay, unit); |
70 | |
} |
71 | |
|
72 | |
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { |
73 | 0 | Callable<V> work = associateWithSubject(callable); |
74 | 0 | return this.targetScheduledExecutorService.schedule(work, delay, unit); |
75 | |
} |
76 | |
|
77 | |
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { |
78 | 0 | Runnable work = associateWithSubject(command); |
79 | 0 | return this.targetScheduledExecutorService.scheduleAtFixedRate(work, initialDelay, period, unit); |
80 | |
} |
81 | |
|
82 | |
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { |
83 | 0 | Runnable work = associateWithSubject(command); |
84 | 0 | return this.targetScheduledExecutorService.scheduleWithFixedDelay(work, initialDelay, delay, unit); |
85 | |
} |
86 | |
} |