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.14
Committed: Thu Jan 18 23:15:09 2001 UTC (23 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.13: +3 -2 lines
Log Message:
Changes to reflect move of Component, ComponentStartException, and the
ReferenceManager from util to componentmanager.

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