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.11
Committed: Thu Dec 7 00:02:17 2000 UTC (23 years, 6 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PACKAGEBUILD
Changes since 1.10: +23 -24 lines
Log Message:
Had a tidy up. The Filter Manager now makes use of the Reference Manager, which
ensures that we don't have lots of messy reference passing.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.9 package uk.ac.ukc.iscream.filtermanager;
3 tdb 1.1
4     //---IMPORTS---
5     import uk.ac.ukc.iscream.core.*;
6 tdb 1.7 import uk.ac.ukc.iscream.filter.*;
7 tdb 1.11 import uk.ac.ukc.iscream.util.*;
8 tdb 1.1 import java.net.Socket;
9     import java.io.*;
10    
11     /**
12 tdb 1.11 * Handles setting up a host.
13 tdb 1.1 *
14 tdb 1.10 * @author $Author: tdb1 $
15 tdb 1.11 * @version $Id: HostInit.java,v 1.10 2000/11/30 02:20:05 tdb1 Exp $
16 tdb 1.1 */
17     class HostInit extends Thread {
18    
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24 tdb 1.11 public final String REVISION = "$Revision: 1.10 $";
25 tdb 1.1
26     //---STATIC METHODS---
27    
28     //---CONSTRUCTORS---
29    
30 tdb 1.11 public HostInit(Socket socket) throws IOException {
31 tdb 1.1 _socket = socket;
32     _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
33     _socketOut = new PrintWriter(_socket.getOutputStream());
34 tdb 1.11 _logger.write(toString(), Logger.SYSINIT, "created");
35 tdb 1.1 }
36    
37     //---PUBLIC METHODS---
38    
39     public void run() {
40     try {
41     String inBound = _socketIn.readLine();
42     if (!inBound.equals("STARTCONFIG")) {
43     _socketOut.println("ERROR");
44     _socketOut.flush();
45 tdb 1.7 throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
46 tdb 1.1 }
47    
48 ajm 1.8 Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
49 tdb 1.1 if (myConfig == null) {
50     _socketOut.println("ERROR");
51 tdb 1.7 throw new IOException("error in host configuration");
52 tdb 1.1 } else {
53     _socketOut.println("OK");
54     _socketOut.flush();
55    
56 tdb 1.2 // get lastmodified
57     inBound = _socketIn.readLine();
58 tdb 1.4 if(!inBound.equals("LASTMODIFIED")) {
59     // protocol error
60 tdb 1.2 _socketOut.println("ERROR");
61     _socketOut.flush();
62 tdb 1.7 throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
63 tdb 1.4 }
64     else {
65     // send info
66     _socketOut.println(myConfig.getLastModified());
67     _socketOut.flush();
68 tdb 1.2 }
69    
70 tdb 1.7 // get config fileList
71     inBound = _socketIn.readLine();
72     if(!inBound.equals("FILELIST")) {
73     // protocol error
74     _socketOut.println("ERROR");
75     _socketOut.flush();
76     throw new IOException("protocol error - expected:FILELIST got:" + inBound);
77     }
78     else {
79     // send info
80     _socketOut.println(myConfig.getFileList());
81     _socketOut.flush();
82     }
83    
84 tdb 1.2 // get properties
85 tdb 1.1 inBound = _socketIn.readLine();
86     while(!inBound.equals("ENDCONFIG")) {
87    
88     // get the property
89     try {
90 tdb 1.10 String returnedProperty = myConfig.getProperty("Host."+inBound);
91 tdb 1.1
92     _socketOut.println(returnedProperty);
93     _socketOut.flush();
94    
95     } catch (org.omg.CORBA.MARSHAL e) {
96     _socketOut.println("ERROR");
97     _socketOut.flush();
98     }
99     inBound = _socketIn.readLine();
100     }
101 tdb 1.11 _logger.write(toString(), Logger.SYSMSG, "configured host");
102 tdb 1.1 _socketOut.println("OK");
103     _socketOut.flush();
104 tdb 1.7
105     // get filter reference
106     inBound = _socketIn.readLine();
107     if(!inBound.equals("FILTER")) {
108     // protocol error
109     _socketOut.println("ERROR");
110     _socketOut.flush();
111     throw new IOException("protocol error - expected:FILTER got:" + inBound);
112     }
113     else {
114     // send info
115     String parentFilter = myConfig.getProperty("Host.filter");
116 tdb 1.11 _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
117     Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
118 tdb 1.7 _socketOut.println(filter.getHostName() + ";"
119     + filter.getUDPPort() + ";"
120     + filter.getTCPPort());
121     _socketOut.flush();
122     }
123    
124     // confirm that all is ok
125     inBound = _socketIn.readLine();
126     if(!inBound.equals("END")) {
127     // protocol error
128     _socketOut.println("ERROR");
129     _socketOut.flush();
130     throw new IOException("protocol error - expected:END got:" + inBound);
131     }
132     else {
133     // send ok
134     _socketOut.println("OK");
135     _socketOut.flush();
136     }
137    
138 tdb 1.1 }
139    
140     } catch (Exception e) {
141 tdb 1.11 _logger.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
142 tdb 1.1 }
143    
144     _socketOut.flush();
145     // Disconnect streams & socket
146     try {
147     _socketIn.close();
148     _socketOut.close();
149     _socket.close();
150     } catch (IOException e) {
151 tdb 1.11 _logger.write(toString(), Logger.ERROR, "exception on socket close");
152 tdb 1.1 }
153 tdb 1.11 _logger.write(toString(), Logger.SYSMSG, "finished");
154 tdb 1.1 }
155    
156     /**
157     * Overrides the {@link java.lang.Object#toString() Object.toString()}
158     * method to provide clean logging (every class should have this).
159     *
160     * @return the name of this class and its CVS revision
161     */
162     public String toString() {
163     return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
164     + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
165    
166     }
167    
168     //---PRIVATE METHODS---
169    
170     //---ACCESSOR/MUTATOR METHODS---
171    
172     //---ATTRIBUTES---
173    
174 tdb 1.11 /**
175     * A reference to the logger the system is using
176     */
177     Logger _logger = ReferenceManager.getInstance().getLogger();
178    
179     /**
180     * A reference to the Configuration Manager the system is using
181     */
182     ConfigurationManager _configManager = ReferenceManager.getInstance().getCM();
183    
184 tdb 1.1 Socket _socket;
185     BufferedReader _socketIn;
186     PrintWriter _socketOut;
187 tdb 1.11
188 tdb 1.1 //---STATIC ATTRIBUTES---
189    
190     }