Source code: konspire/common/NamedErrorHandlingThread.java
1 // Jason Rohrer
2 // NamedErrorHandlingThread.java
3
4 /**
5 *
6 * Thread class that catches errors thrown by the run method and passes
7 * them to the error handling framework. Thread names are also enforced.
8 *
9 * Created 8-23-2000
10 * Mods:
11 */
12
13 package konspire.common;
14
15
16 /**
17 * Thread class that catches <code>Throwable</code>s thrown by the run
18 * methods of all subclasses. <code>Throwables</code> are reported to the
19 * error handling framework. All subclassing <code>Thread</code>s are
20 * required to pass in a name for themselves.
21 * <p>
22 * Note that all constructors require a non-null name to be passed in.
23 * Thus, other <code>Thread</code> constructors are not overridden.
24 *
25 * @author Jason Rohrer
26 */
27 public abstract class NamedErrorHandlingThread extends ErrorHandlingThread {
28
29
30
31 /**
32 * Constructs a <code>NamedErrorHandlingThread</code>.
33 *
34 * @param inName name of this <code>Thread</code>. Must
35 * be non-null.
36 */
37 protected NamedErrorHandlingThread( String inName ) {
38 super( checkName( inName ) );
39 }
40
41
42
43 /**
44 * Constructs a <code>NamedErrorHandlingThread</code>, specifying
45 * a <code>Runnable</code>.
46 *
47 * @param inRunnable the runnable to be run by this <code>Thread</code>.
48 * @param inName name of this <code>Thread</code>. Must
49 * be non-null.
50 */
51 protected NamedErrorHandlingThread( Runnable inRunnable, String inName ) {
52 super( inRunnable, checkName( inName ) );
53 }
54
55
56
57 /**
58 * Constructs a <code>NamedErrorHandlingThread</code>, specifying
59 * a <code>ThreadGroup</code>.
60 *
61 * @param inGroup the <code>ThreadGroup</code> for this <code>Thread</code>.
62 * @param inRunnable the <code>Runnable</code> to be run by this <code>Thread</code>.
63 * @param inName name of this <code>Thread</code>. Must
64 * be non-null.
65 */
66 protected NamedErrorHandlingThread( ThreadGroup inGroup, String inName ) {
67 super( inGroup, checkName( inName ) );
68 }
69
70
71
72 /**
73 * Constructs a <code>NamedErrorHandlingThread</code>, specifying
74 * a <code>Runnable</code> and a <code>ThreadGroup</code>.
75 *
76 * @param inGroup the <code>ThreadGroup</code> for this <code>Thread</code>.
77 * @param inRunnable the <code>Runnable</code> to be run by this <code>Thread</code>.
78 * @param inName name of this <code>Thread</code>. Must
79 * be non-null.
80 */
81 protected NamedErrorHandlingThread( ThreadGroup inGroup,
82 Runnable inRunnable, String inName ) {
83
84 super( inGroup, inRunnable, checkName( inName ) );
85 }
86
87
88
89 /**
90 * Checks that a <code>Thread</code> name is non-<code>null</code>.
91 * Throws an <code>IllegalArgumentException</code> if the name is
92 * <code>null</code>.
93 * Note that the exception is not declared by this method.
94 *
95 * @param inName name to check for non-<code>null</code> property.
96 *
97 * @return the passed in name (for convienience).
98 */
99 private static String checkName( String inName ) {
100 if( inName == null ) {
101 throw new IllegalArgumentException(
102 "Thread name must not be null" );
103 }
104 return inName;
105 }
106
107 }