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
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostInit.java (file contents):
Revision 1.10 by tdb, Thu Nov 30 02:20:05 2000 UTC vs.
Revision 1.20 by tdb, Wed Feb 28 10:37:46 2001 UTC

# Line 4 | Line 4 | package uk.ac.ukc.iscream.filtermanager;
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.core.*;
6   import uk.ac.ukc.iscream.filter.*;
7 < import java.net.Socket;
8 < import java.io.InputStream;
9 < import java.io.OutputStream;
10 < import java.io.IOException;
7 > import uk.ac.ukc.iscream.util.*;
8 > import uk.ac.ukc.iscream.componentmanager.*;
9 > import java.net.*;
10   import java.io.*;
12 import org.omg.CORBA.*;
13 import org.omg.CosNaming.*;
11  
12   /**
13 < * <ONE LINE DESCRIPTION>
14 < * <DETAILED DESCRIPTION>
13 > * Handles setting up a host.
14 > * This class provides a host with appropriate configuration
15 > * and a reference to a Filter to which it should pass data.
16   *
17   * @author  $Author$
18   * @version $Id$
# Line 32 | Line 30 | class HostInit extends Thread {
30  
31   //---CONSTRUCTORS---
32  
33 <    public HostInit(Socket socket, ConfigurationManager configManager, Logger logRef, NamingContextExt ncRef) throws IOException {
34 <        _configManager = configManager;
35 <        _logRef = logRef;
33 >    /**
34 >     * Construct a new HostInit.
35 >     *
36 >     * @param socket The socket to which the host is connected
37 >     */
38 >    public HostInit(Socket socket) throws IOException {
39          _socket = socket;
40 <        _ncRef = ncRef;
40 >        // setup reader & writer
41          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
42 <        _socketOut = new PrintWriter(_socket.getOutputStream());
43 <        _logRef.write(toString(), Logger.SYSINIT, "created");
42 >        _socketOut = new PrintWriter(_socket.getOutputStream(), true);
43 >        _logger.write(toString(), Logger.SYSINIT, "created");
44      }
45      
46   //---PUBLIC METHODS---
47  
48 +    /**
49 +     * Main method in this class, which handles communicating with
50 +     * the host to determine it's setup.
51 +     */
52      public void run() {
53          try {
54              String inBound = _socketIn.readLine();
55              if (!inBound.equals("STARTCONFIG")) {
56                  _socketOut.println("ERROR");
52                _socketOut.flush();
57                  throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
58              }
59  
# Line 59 | Line 63 | class HostInit extends Thread {
63                  throw new IOException("error in host configuration");
64              } else {
65                  _socketOut.println("OK");
62                _socketOut.flush();
66                  
67                  // get lastmodified
68                  inBound = _socketIn.readLine();
69                  if(!inBound.equals("LASTMODIFIED")) {
70                          // protocol error
71                      _socketOut.println("ERROR");
69                    _socketOut.flush();
72                      throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
73                  }
74                  else {
75                          // send info
76                          _socketOut.println(myConfig.getLastModified());
75                        _socketOut.flush();
77                  }
78                  
79                  // get config fileList
# Line 80 | Line 81 | class HostInit extends Thread {
81                  if(!inBound.equals("FILELIST")) {
82                          // protocol error
83                      _socketOut.println("ERROR");
83                    _socketOut.flush();
84                      throw new IOException("protocol error - expected:FILELIST got:" + inBound);
85                  }
86                  else {
87                          // send info
88                          _socketOut.println(myConfig.getFileList());
89                        _socketOut.flush();
89                  }
90 <
90 >                
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 >                    // send the fqdn (of the host) to the host
100 >                    _socketOut.println(_socket.getInetAddress().getHostName());
101 >                }
102 >                
103                  // get properties
104                  inBound = _socketIn.readLine();
105                  while(!inBound.equals("ENDCONFIG")) {
# Line 98 | Line 109 | class HostInit extends Thread {
109                          String returnedProperty = myConfig.getProperty("Host."+inBound);    
110                          
111                          _socketOut.println(returnedProperty);
101                        _socketOut.flush();
112      
113                      } catch (org.omg.CORBA.MARSHAL e) {
114                          _socketOut.println("ERROR");
105                        _socketOut.flush();
115                      }
116                      inBound = _socketIn.readLine();
117                  }
118 <                _logRef.write(toString(), Logger.SYSMSG, "configured host");
118 >                _logger.write(toString(), Logger.SYSMSG, "configured host");
119                  _socketOut.println("OK");
111                _socketOut.flush();
120                  
121                  // get filter reference
122                  inBound = _socketIn.readLine();
123                  if(!inBound.equals("FILTER")) {
124                          // protocol error
125                      _socketOut.println("ERROR");
118                    _socketOut.flush();
126                      throw new IOException("protocol error - expected:FILTER got:" + inBound);
127                  }
128                  else {
129                          // send info
130                          String parentFilter =  myConfig.getProperty("Host.filter");
131 <                        _logRef.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
132 <                        org.omg.CORBA.Object objRef = _ncRef.resolve(_ncRef.to_name("iscream.Filter." + parentFilter));
126 <                    Filter filter = FilterHelper.narrow(objRef);
131 >                        _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
132 >                    Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
133                          _socketOut.println(filter.getHostName() + ";"
134                                           + filter.getUDPPort() + ";"
135                                           + filter.getTCPPort());
130                        _socketOut.flush();
136                  }
137                  
138                  // confirm that all is ok
# Line 135 | Line 140 | class HostInit extends Thread {
140                  if(!inBound.equals("END")) {
141                          // protocol error
142                      _socketOut.println("ERROR");
138                    _socketOut.flush();
143                      throw new IOException("protocol error - expected:END got:" + inBound);
144                  }
145                  else {
146                          // send ok
147                          _socketOut.println("OK");
144                        _socketOut.flush();
148                  }
149  
150              }
151              
152          } catch (Exception e) {
153 <            _logRef.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
153 >            _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
154          }
155          
156          _socketOut.flush();
# Line 157 | Line 160 | class HostInit extends Thread {
160              _socketOut.close();
161              _socket.close();
162          } catch (IOException e) {
163 <            _logRef.write(toString(), Logger.ERROR, "exception on socket close");
163 >            _logger.write(toString(), Logger.ERROR, "exception on socket close");
164          }
165 <        _logRef.write(toString(), Logger.SYSMSG, "finished");
165 >        _logger.write(toString(), Logger.SYSMSG, "finished");
166      }
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 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
173 +     * to format the toString()
174 +     *
175       * @return the name of this class and its CVS revision
176       */
177      public String toString() {
178 <        return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
179 <         + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
180 <        
178 >        return FormatName.getName(
179 >            _name,
180 >            getClass().getName(),
181 >            REVISION);
182      }
183  
184   //---PRIVATE METHODS---
# Line 180 | Line 187 | class HostInit extends Thread {
187  
188   //---ATTRIBUTES---
189  
190 <    ConfigurationManager _configManager;
191 <    Logger _logRef;
192 <    Socket _socket;
193 <    BufferedReader _socketIn;
194 <    PrintWriter _socketOut;
195 <    NamingContextExt _ncRef;
190 >    /**
191 >     * This holds a reference to the
192 >     * system logger that is being used.
193 >     */
194 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
195 >    
196 >    /**
197 >     * A reference to the Configuration Manager the system is using
198 >     */
199 >    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 >    
222 >    /**
223 >     * Used for the output stream of this socket
224 >     */
225 >    private PrintWriter _socketOut;
226 >
227   //---STATIC ATTRIBUTES---
228  
229   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines