-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathSchedulableActionContext.java
89 lines (78 loc) · 2.06 KB
/
SchedulableActionContext.java
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
package jalse.actions;
import java.util.concurrent.TimeUnit;
/**
* A mutable extension of {@link ActionContext}. This can be supplied at the appropriate level for
* an editable context.<br>
* <br>
* Actions can be scheduled ({@link #schedule()}) and awaited ({@link #await()}) from this level.
*
* @author Elliot Ford
* @param <T>
* Actor type (can be {@code ?} if no actor).
*
*/
public interface SchedulableActionContext<T> extends ActionContext<T> {
/**
* Gets the action this context is for.
*
* @return Action.
*/
Action<T> getAction();
/**
* Gets the initial delay.
*
* @param unit
* TimeUnit to convert to.
* @return Initial delay in the supplied unit.
*/
long getInitialDelay(TimeUnit unit);
/**
* Schedules the action for execution.
*/
void schedule();
/**
* This is a convenience method for scheduling and then awaiting execution (or cancellation) of
* the action.
*
* @throws InterruptedException
* If the current thread was interrupted.
*/
default void scheduleAndAwait() throws InterruptedException {
schedule();
if (!isDone()) {
await();
}
}
/**
* Sets the referenced actor.
*
* @param actor
* Actor.
*/
void setActor(T actor);
/**
* Sets the initial delay.
*
* @param initialDelay
* Initial delay to set (can be {@code 0}).
* @param unit
* TimeUnit delay is in.
*/
void setInitialDelay(long initialDelay, TimeUnit unit);
/**
* Sets the period.
*
* @param period
* Period to set (can be {@code 0}).
* @param unit
* TimeUnit period is in.
*/
void setPeriod(long period, TimeUnit unit);
/**
* Sets whether the action continues to reschedule after an exception.
*
* @param periodicOnException
* Whether the action should continue.
*/
void setPeriodicOnException(boolean periodicOnException);
}