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 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 synchronized (this) {
18 this.closeListener = closeListener;
19 }
20 }
21
22 /***
23 * Call the close listener if we have one.
24 */
25 protected final void onClose() {
26 synchronized (this) {
27 if (closeListener != null) {
28 closeListener.onClose();
29 }
30 }
31 }
32 }