Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractSpawnable |
|
| 1.5;1,5 |
1 | package expectj; | |
2 | ||
3 | ||
4 | /** | |
5 | * Base class for spawnables providing an {@link #onClose()} method that should | |
6 | * be called on close. | |
7 | * | |
8 | * @author johan.walles@gmail.com | |
9 | */ | |
10 | 4105 | public abstract class AbstractSpawnable implements Spawnable { |
11 | /** | |
12 | * If non-null, will be notified {@link #onClose()}. | |
13 | */ | |
14 | private CloseListener closeListener; | |
15 | ||
16 | public void setCloseListener(CloseListener closeListener) { | |
17 | 3065 | synchronized (this) { |
18 | 3065 | this.closeListener = closeListener; |
19 | 3065 | } |
20 | 3065 | } |
21 | ||
22 | /** | |
23 | * Call the close listener if we have one. | |
24 | */ | |
25 | protected final void onClose() { | |
26 | 3070 | synchronized (this) { |
27 | 3070 | if (closeListener != null) { |
28 | 132 | closeListener.onClose(); |
29 | } | |
30 | 3070 | } |
31 | 3070 | } |
32 | } |