1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
|
|
|
3 |
|
|
//---IMPORTS--- |
4 |
|
|
import java.io.IOException; |
5 |
|
|
import java.net.Socket; |
6 |
|
|
|
7 |
|
|
/** |
8 |
|
|
* An abstract class providing basic socket handling functionality |
9 |
|
|
* |
10 |
|
|
* @author $Author: tdb1 $ |
11 |
|
|
* @version $Id: TemplateClass.java,v 1.11 2001/03/22 21:50:41 tdb1 Exp $ |
12 |
|
|
*/ |
13 |
|
|
abstract class Handler extends Thread { |
14 |
|
|
|
15 |
|
|
//---FINAL / FINAL STATIC ATTRIBUTES--- |
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* The current CVS revision of this class |
19 |
|
|
*/ |
20 |
|
|
public static final String REVISION = "$Revision: 1.11 $"; |
21 |
|
|
|
22 |
|
|
//---STATIC METHODS--- |
23 |
|
|
|
24 |
|
|
//---CONSTRUCTORS--- |
25 |
|
|
|
26 |
|
|
public Handler(Socket socket) throws IOException { |
27 |
|
|
_socket = socket; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
//---PUBLIC METHODS--- |
31 |
|
|
|
32 |
|
|
/** |
33 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
34 |
|
|
* method to provide clean logging (every class should have this). |
35 |
|
|
* |
36 |
|
|
* This uses the uk.ac.ukc.iscream.util.FormatName class |
37 |
|
|
* to format the toString() |
38 |
|
|
* |
39 |
|
|
* @return the name of this class and its CVS revision |
40 |
|
|
*/ |
41 |
|
|
public String toString() { |
42 |
|
|
return FormatName.getName( |
43 |
|
|
_name, |
44 |
|
|
getClass().getName(), |
45 |
|
|
REVISION); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
//---PRIVATE/PROTECTED METHODS--- |
49 |
|
|
|
50 |
|
|
protected void shutdownSocket() { |
51 |
|
|
// Disconnect streams & socket |
52 |
|
|
try { |
53 |
|
|
_socket.close(); |
54 |
|
|
} catch (IOException e) { |
55 |
|
|
_logger.write(toString(), Logger.ERROR, "exception on socket close"); |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
60 |
|
|
|
61 |
|
|
//---ATTRIBUTES--- |
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* This is the friendly identifier of the |
65 |
|
|
* component this class is running in. |
66 |
|
|
* eg, a Filter may be called "filter1", |
67 |
|
|
* If this class does not have an owning |
68 |
|
|
* component, a name from the configuration |
69 |
|
|
* can be placed here. This name could also |
70 |
|
|
* be changed to null for utility classes. |
71 |
|
|
*/ |
72 |
|
|
private String _name = null; |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* This holds a reference to the |
76 |
|
|
* system logger that is being used. |
77 |
|
|
*/ |
78 |
|
|
private Logger _logger = Logger.getInstance(); |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* The socket this class uses |
82 |
|
|
*/ |
83 |
|
|
protected Socket _socket; |
84 |
|
|
|
85 |
|
|
//---STATIC ATTRIBUTES--- |
86 |
|
|
|
87 |
|
|
} |