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