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.1
Committed: Mon Nov 13 20:40:40 2000 UTC (23 years, 6 months ago) by tdb
Branch: MAIN
Log Message:
Initial check in of the FilterManager

Current support for Host connections and passing back configuration.

Support missing for filter contacting etc.

Not finished or fully commented.

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     * @version $Id: TemplateClass.java,v 1.5 2000/11/13 18:20:09 tdb1 Exp $
17     */
18     class HostInit extends Thread {
19    
20     //---FINAL ATTRIBUTES---
21    
22     /**
23     * The current CVS revision of this class
24     */
25     public final String REVISION = "$Revision: 1.5 $";
26    
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     inBound = _socketIn.readLine();
60     while(!inBound.equals("ENDCONFIG")) {
61    
62     // get the property
63     try {
64     String returnedProperty = myConfig.getProperty(inBound);
65    
66     _socketOut.println(returnedProperty);
67     _socketOut.flush();
68    
69     } catch (org.omg.CORBA.MARSHAL e) {
70     _socketOut.println("ERROR");
71     _socketOut.flush();
72     }
73     inBound = _socketIn.readLine();
74     }
75     _logger.write(toString(), "configured host");
76     _socketOut.println("OK");
77     _socketOut.flush();
78     }
79    
80     } catch (Exception e) {
81     _logger.write(toString(), e.toString());
82     }
83    
84     _socketOut.flush();
85     // Disconnect streams & socket
86     try {
87     _socketIn.close();
88     _socketOut.close();
89     _socket.close();
90     } catch (IOException e) {
91     _logger.write(toString(), "exception on socket close");
92     }
93     _logger.write(toString(), "finished");
94     }
95    
96     /**
97     * Overrides the {@link java.lang.Object#toString() Object.toString()}
98     * method to provide clean logging (every class should have this).
99     *
100     * @return the name of this class and its CVS revision
101     */
102     public String toString() {
103     return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
104     + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
105    
106     }
107    
108     //---PRIVATE METHODS---
109    
110     //---ACCESSOR/MUTATOR METHODS---
111    
112     //---ATTRIBUTES---
113    
114     Configurator _configurator;
115     Logger _logger;
116     Socket _socket;
117     BufferedReader _socketIn;
118     PrintWriter _socketOut;
119    
120     //---STATIC ATTRIBUTES---
121    
122     }