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 public SubjectAwareScheduledExecutorService() {
32 }
33
34 public SubjectAwareScheduledExecutorService(ScheduledExecutorService target) {
35 setTargetScheduledExecutorService(target);
36 }
37
38 public ScheduledExecutorService getTargetScheduledExecutorService() {
39 return targetScheduledExecutorService;
40 }
41
42 public void setTargetScheduledExecutorService(ScheduledExecutorService targetScheduledExecutorService) {
43 super.setTargetExecutorService(targetScheduledExecutorService);
44 this.targetScheduledExecutorService = targetScheduledExecutorService;
45 }
46
47 @Override
48 public void setTargetExecutor(Executor targetExecutor) {
49 if (!(targetExecutor instanceof ScheduledExecutorService)) {
50 String msg = "The " + getClass().getName() + " implementation only accepts " +
51 ScheduledExecutorService.class.getName() + " target instances.";
52 throw new IllegalArgumentException(msg);
53 }
54 super.setTargetExecutorService((ScheduledExecutorService) targetExecutor);
55 }
56
57 @Override
58 public void setTargetExecutorService(ExecutorService targetExecutorService) {
59 if (!(targetExecutorService instanceof ScheduledExecutorService)) {
60 String msg = "The " + getClass().getName() + " implementation only accepts " +
61 ScheduledExecutorService.class.getName() + " target instances.";
62 throw new IllegalArgumentException(msg);
63 }
64 super.setTargetExecutorService(targetExecutorService);
65 }
66
67 public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
68 Runnable work = associateWithSubject(command);
69 return this.targetScheduledExecutorService.schedule(work, delay, unit);
70 }
71
72 public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
73 Callable<V> work = associateWithSubject(callable);
74 return this.targetScheduledExecutorService.schedule(work, delay, unit);
75 }
76
77 public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
78 Runnable work = associateWithSubject(command);
79 return this.targetScheduledExecutorService.scheduleAtFixedRate(work, initialDelay, period, unit);
80 }
81
82 public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
83 Runnable work = associateWithSubject(command);
84 return this.targetScheduledExecutorService.scheduleWithFixedDelay(work, initialDelay, delay, unit);
85 }
86 }