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.20
Committed: Wed Feb 28 10:37:46 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.19: +4 -10 lines
Log Message:
Don't need to try/catch anymore.

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.14 import uk.ac.ukc.iscream.componentmanager.*;
9 tdb 1.18 import java.net.*;
10 tdb 1.1 import java.io.*;
11    
12     /**
13 tdb 1.11 * Handles setting up a host.
14 ajm 1.12 * This class provides a host with appropriate configuration
15     * and a reference to a Filter to which it should pass data.
16 tdb 1.1 *
17 tdb 1.15 * @author $Author: tdb1 $
18 tdb 1.20 * @version $Id: HostInit.java,v 1.19 2001/02/28 10:36:05 tdb1 Exp $
19 tdb 1.1 */
20     class HostInit extends Thread {
21    
22     //---FINAL ATTRIBUTES---
23    
24     /**
25     * The current CVS revision of this class
26     */
27 tdb 1.20 public final String REVISION = "$Revision: 1.19 $";
28 tdb 1.1
29     //---STATIC METHODS---
30    
31     //---CONSTRUCTORS---
32    
33 tdb 1.15 /**
34     * Construct a new HostInit.
35     *
36     * @param socket The socket to which the host is connected
37     */
38 tdb 1.11 public HostInit(Socket socket) throws IOException {
39 tdb 1.1 _socket = socket;
40 tdb 1.15 // setup reader & writer
41 tdb 1.1 _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
42 tdb 1.16 _socketOut = new PrintWriter(_socket.getOutputStream(), true);
43 tdb 1.11 _logger.write(toString(), Logger.SYSINIT, "created");
44 tdb 1.1 }
45    
46     //---PUBLIC METHODS---
47    
48 tdb 1.15 /**
49     * Main method in this class, which handles communicating with
50     * the host to determine it's setup.
51     */
52 tdb 1.1 public void run() {
53     try {
54     String inBound = _socketIn.readLine();
55     if (!inBound.equals("STARTCONFIG")) {
56     _socketOut.println("ERROR");
57 tdb 1.7 throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
58 tdb 1.1 }
59    
60 ajm 1.8 Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
61 tdb 1.1 if (myConfig == null) {
62     _socketOut.println("ERROR");
63 tdb 1.7 throw new IOException("error in host configuration");
64 tdb 1.1 } else {
65     _socketOut.println("OK");
66    
67 tdb 1.2 // get lastmodified
68     inBound = _socketIn.readLine();
69 tdb 1.4 if(!inBound.equals("LASTMODIFIED")) {
70     // protocol error
71 tdb 1.2 _socketOut.println("ERROR");
72 tdb 1.7 throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
73 tdb 1.4 }
74     else {
75     // send info
76     _socketOut.println(myConfig.getLastModified());
77 tdb 1.2 }
78    
79 tdb 1.7 // get config fileList
80     inBound = _socketIn.readLine();
81     if(!inBound.equals("FILELIST")) {
82     // protocol error
83     _socketOut.println("ERROR");
84     throw new IOException("protocol error - expected:FILELIST got:" + inBound);
85     }
86     else {
87     // send info
88     _socketOut.println(myConfig.getFileList());
89     }
90 tdb 1.18
91     // send the FQDN to the host
92     inBound = _socketIn.readLine();
93     if(!inBound.equals("FQDN")) {
94     // protocol error
95     _socketOut.println("ERROR");
96     throw new IOException("protocol error - expected:FQDN got:" + inBound);
97     }
98     else {
99 tdb 1.20 // send the fqdn (of the host) to the host
100     _socketOut.println(_socket.getInetAddress().getHostName());
101 tdb 1.18 }
102    
103 tdb 1.2 // get properties
104 tdb 1.1 inBound = _socketIn.readLine();
105     while(!inBound.equals("ENDCONFIG")) {
106    
107     // get the property
108     try {
109 tdb 1.10 String returnedProperty = myConfig.getProperty("Host."+inBound);
110 tdb 1.1
111     _socketOut.println(returnedProperty);
112    
113     } catch (org.omg.CORBA.MARSHAL e) {
114     _socketOut.println("ERROR");
115     }
116     inBound = _socketIn.readLine();
117     }
118 tdb 1.11 _logger.write(toString(), Logger.SYSMSG, "configured host");
119 tdb 1.1 _socketOut.println("OK");
120 tdb 1.7
121     // get filter reference
122     inBound = _socketIn.readLine();
123     if(!inBound.equals("FILTER")) {
124     // protocol error
125     _socketOut.println("ERROR");
126     throw new IOException("protocol error - expected:FILTER got:" + inBound);
127     }
128     else {
129     // send info
130     String parentFilter = myConfig.getProperty("Host.filter");
131 tdb 1.11 _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
132     Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
133 tdb 1.7 _socketOut.println(filter.getHostName() + ";"
134     + filter.getUDPPort() + ";"
135     + filter.getTCPPort());
136     }
137    
138     // confirm that all is ok
139     inBound = _socketIn.readLine();
140     if(!inBound.equals("END")) {
141     // protocol error
142     _socketOut.println("ERROR");
143     throw new IOException("protocol error - expected:END got:" + inBound);
144     }
145     else {
146     // send ok
147     _socketOut.println("OK");
148     }
149    
150 tdb 1.1 }
151    
152     } catch (Exception e) {
153 tdb 1.17 _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
154 tdb 1.1 }
155    
156     _socketOut.flush();
157     // Disconnect streams & socket
158     try {
159     _socketIn.close();
160     _socketOut.close();
161     _socket.close();
162     } catch (IOException e) {
163 tdb 1.11 _logger.write(toString(), Logger.ERROR, "exception on socket close");
164 tdb 1.1 }
165 tdb 1.11 _logger.write(toString(), Logger.SYSMSG, "finished");
166 tdb 1.1 }
167    
168     /**
169     * Overrides the {@link java.lang.Object#toString() Object.toString()}
170     * method to provide clean logging (every class should have this).
171     *
172 ajm 1.12 * This uses the uk.ac.ukc.iscream.util.NameFormat class
173     * to format the toString()
174     *
175 tdb 1.1 * @return the name of this class and its CVS revision
176     */
177     public String toString() {
178 ajm 1.12 return FormatName.getName(
179     _name,
180 ajm 1.13 getClass().getName(),
181 ajm 1.12 REVISION);
182 tdb 1.1 }
183    
184     //---PRIVATE METHODS---
185    
186     //---ACCESSOR/MUTATOR METHODS---
187    
188     //---ATTRIBUTES---
189    
190 tdb 1.11 /**
191 ajm 1.12 * This holds a reference to the
192     * system logger that is being used.
193 tdb 1.11 */
194 ajm 1.12 private Logger _logger = ReferenceManager.getInstance().getLogger();
195 tdb 1.11
196     /**
197     * A reference to the Configuration Manager the system is using
198     */
199 ajm 1.12 private ConfigurationManager _configManager = ReferenceManager.getInstance().getCM();
200    
201     /**
202     * This is the friendly identifier of the
203     * component this class is running in.
204     * eg, a Filter may be called "filter1",
205     * If this class does not have an owning
206     * component, a name from the configuration
207     * can be placed here. This name could also
208     * be changed to null for utility classes.
209     */
210     private String _name = FilterManager.NAME;
211    
212     /**
213     * The socket this class uses
214     */
215     private Socket _socket;
216    
217     /**
218     * Used for the input stream of this socket
219     */
220     private BufferedReader _socketIn;
221 tdb 1.11
222 ajm 1.12 /**
223     * Used for the output stream of this socket
224     */
225     private PrintWriter _socketOut;
226 tdb 1.11
227 tdb 1.1 //---STATIC ATTRIBUTES---
228    
229     }