ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostInit.java
Revision: 1.3
Committed: Wed Nov 15 00:39:07 2000 UTC (23 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.2: +4 -3 lines
Log Message:
Stupid mistake. :-(

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2    
3     //---IMPORTS---
4     import uk.ac.ukc.iscream.core.*;
5     import java.net.Socket;
6     import java.io.InputStream;
7     import java.io.OutputStream;
8     import java.io.IOException;
9     import java.io.*;
10    
11     /**
12     * <ONE LINE DESCRIPTION>
13     * <DETAILED DESCRIPTION>
14     *
15     * @author $Author: tdb1 $
16 tdb 1.3 * @version $Id: HostInit.java,v 1.2 2000/11/15 00:33:12 tdb1 Exp $
17 tdb 1.1 */
18     class HostInit extends Thread {
19    
20     //---FINAL ATTRIBUTES---
21    
22     /**
23     * The current CVS revision of this class
24     */
25 tdb 1.3 public final String REVISION = "$Revision: 1.2 $";
26 tdb 1.1
27     //---STATIC METHODS---
28    
29     //---CONSTRUCTORS---
30    
31     public HostInit(Socket socket, Configurator configurator, Logger logger) throws IOException {
32     _configurator = configurator;
33     _logger = logger;
34     _socket = socket;
35     _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
36     _socketOut = new PrintWriter(_socket.getOutputStream());
37     _logger.write(toString(), "created");
38     }
39    
40     //---PUBLIC METHODS---
41    
42     public void run() {
43     try {
44     String inBound = _socketIn.readLine();
45     if (!inBound.equals("STARTCONFIG")) {
46     _socketOut.println("ERROR");
47     _socketOut.flush();
48     throw new IOException("Protocol Error");
49     }
50    
51     Configuration myConfig = _configurator.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase());
52     if (myConfig == null) {
53     _socketOut.println("ERROR");
54     throw new IOException("No Configuration File For Host");
55     } else {
56     _socketOut.println("OK");
57     _socketOut.flush();
58    
59 tdb 1.2 // get lastmodified
60     inBound = _socketIn.readLine();
61 tdb 1.3 while(!inBound.equals("LASTMODIFIED")) {
62 tdb 1.2 _socketOut.println("ERROR");
63     _socketOut.flush();
64 tdb 1.3 inBound = _socketIn.readLine();
65 tdb 1.2 }
66     _socketOut.println(myConfig.getLastModified());
67     _socketOut.flush();
68    
69     // get properties
70 tdb 1.1 inBound = _socketIn.readLine();
71     while(!inBound.equals("ENDCONFIG")) {
72    
73     // get the property
74     try {
75     String returnedProperty = myConfig.getProperty(inBound);
76    
77     _socketOut.println(returnedProperty);
78     _socketOut.flush();
79    
80     } catch (org.omg.CORBA.MARSHAL e) {
81     _socketOut.println("ERROR");
82     _socketOut.flush();
83     }
84     inBound = _socketIn.readLine();
85     }
86     _logger.write(toString(), "configured host");
87     _socketOut.println("OK");
88     _socketOut.flush();
89     }
90    
91     } catch (Exception e) {
92     _logger.write(toString(), e.toString());
93     }
94    
95     _socketOut.flush();
96     // Disconnect streams & socket
97     try {
98     _socketIn.close();
99     _socketOut.close();
100     _socket.close();
101     } catch (IOException e) {
102     _logger.write(toString(), "exception on socket close");
103     }
104     _logger.write(toString(), "finished");
105     }
106    
107     /**
108     * Overrides the {@link java.lang.Object#toString() Object.toString()}
109     * method to provide clean logging (every class should have this).
110     *
111     * @return the name of this class and its CVS revision
112     */
113     public String toString() {
114     return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
115     + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
116    
117     }
118    
119     //---PRIVATE METHODS---
120    
121     //---ACCESSOR/MUTATOR METHODS---
122    
123     //---ATTRIBUTES---
124    
125     Configurator _configurator;
126     Logger _logger;
127     Socket _socket;
128     BufferedReader _socketIn;
129     PrintWriter _socketOut;
130    
131     //---STATIC ATTRIBUTES---
132    
133     }