1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.rolling.helper;
18
19 import java.io.IOException;
20
21
22 /***
23 * Abstract base class for implementations of Action.
24 *
25 * @author Curt Arnold
26 */
27 public abstract class ActionBase implements Action {
28 /***
29 * Is action complete.
30 */
31 private boolean complete = false;
32
33 /***
34 * Is action interrupted.
35 */
36 private boolean interrupted = false;
37
38 /***
39 * Constructor.
40 */
41 protected ActionBase() {
42 }
43
44 /***
45 * Perform action.
46 *
47 * @throws IOException if IO error.
48 * @return true if successful.
49 */
50 public abstract boolean execute() throws IOException;
51
52 /***
53 * {@inheritDoc}
54 */
55 public synchronized void run() {
56 if (!interrupted) {
57 try {
58 execute();
59 } catch (IOException ex) {
60 reportException(ex);
61 }
62
63 complete = true;
64 interrupted = true;
65 }
66 }
67
68 /***
69 * {@inheritDoc}
70 */
71 public synchronized void close() {
72 interrupted = true;
73 }
74
75 /***
76 * Tests if the action is complete.
77 * @return true if action is complete.
78 */
79 public boolean isComplete() {
80 return complete;
81 }
82
83 /***
84 * Capture exception.
85 *
86 * @param ex exception.
87 */
88 protected void reportException(final Exception ex) {
89 }
90 }