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.2 by tdb, Wed Nov 15 00:33:12 2000 UTC vs.
Revision 1.8 by ajm, Mon Nov 27 23:09:06 2000 UTC

# Line 2 | Line 2
2  
3   //---IMPORTS---
4   import uk.ac.ukc.iscream.core.*;
5 + import uk.ac.ukc.iscream.filter.*;
6   import java.net.Socket;
7   import java.io.InputStream;
8   import java.io.OutputStream;
9   import java.io.IOException;
10   import java.io.*;
11 + import org.omg.CORBA.*;
12 + import org.omg.CosNaming.*;
13  
14   /**
15   * <ONE LINE DESCRIPTION>
# Line 28 | Line 31 | class HostInit extends Thread {
31  
32   //---CONSTRUCTORS---
33  
34 <    public HostInit(Socket socket, Configurator configurator, Logger logger) throws IOException {
35 <        _configurator = configurator;
36 <        _logger = logger;
34 >    public HostInit(Socket socket, ConfigurationManager configManager, Logger logRef, NamingContextExt ncRef) throws IOException {
35 >        _configManager = configManager;
36 >        _logRef = logRef;
37          _socket = socket;
38 +        _ncRef = ncRef;
39          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
40          _socketOut = new PrintWriter(_socket.getOutputStream());
41 <        _logger.write(toString(), "created");
41 >        _logRef.write(toString(), Logger.SYSINIT, "created");
42      }
43      
44   //---PUBLIC METHODS---
# Line 45 | Line 49 | class HostInit extends Thread {
49              if (!inBound.equals("STARTCONFIG")) {
50                  _socketOut.println("ERROR");
51                  _socketOut.flush();
52 <                throw new IOException("Protocol Error");
52 >                throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
53              }
54  
55 <            Configuration myConfig = _configurator.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase());
55 >            Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
56              if (myConfig == null) {
57                  _socketOut.println("ERROR");
58 <                throw new IOException("No Configuration File For Host");
58 >                throw new IOException("error in host configuration");
59              } else {
60                  _socketOut.println("OK");
61                  _socketOut.flush();
62                  
63                  // get lastmodified
64                  inBound = _socketIn.readLine();
65 <                while(!inBound.equals("LASTMODIFIED")) {
65 >                if(!inBound.equals("LASTMODIFIED")) {
66 >                        // protocol error
67                      _socketOut.println("ERROR");
68                      _socketOut.flush();
69 +                    throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
70                  }
71 <                _socketOut.println(myConfig.getLastModified());
72 <                _socketOut.flush();
71 >                else {
72 >                        // send info
73 >                        _socketOut.println(myConfig.getLastModified());
74 >                        _socketOut.flush();
75 >                }
76                  
77 +                // get config fileList
78 +                inBound = _socketIn.readLine();
79 +                if(!inBound.equals("FILELIST")) {
80 +                        // protocol error
81 +                    _socketOut.println("ERROR");
82 +                    _socketOut.flush();
83 +                    throw new IOException("protocol error - expected:FILELIST got:" + inBound);
84 +                }
85 +                else {
86 +                        // send info
87 +                        _socketOut.println(myConfig.getFileList());
88 +                        _socketOut.flush();
89 +                }
90 +
91                  // get properties
92                  inBound = _socketIn.readLine();
93                  while(!inBound.equals("ENDCONFIG")) {
# Line 82 | Line 105 | class HostInit extends Thread {
105                      }
106                      inBound = _socketIn.readLine();
107                  }
108 <                _logger.write(toString(), "configured host");
108 >                _logRef.write(toString(), Logger.SYSMSG, "configured host");
109                  _socketOut.println("OK");
110                  _socketOut.flush();
111 +                
112 +                // get filter reference
113 +                inBound = _socketIn.readLine();
114 +                if(!inBound.equals("FILTER")) {
115 +                        // protocol error
116 +                    _socketOut.println("ERROR");
117 +                    _socketOut.flush();
118 +                    throw new IOException("protocol error - expected:FILTER got:" + inBound);
119 +                }
120 +                else {
121 +                        // send info
122 +                        String parentFilter =  myConfig.getProperty("Host.filter");
123 +                        _logRef.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
124 +                        org.omg.CORBA.Object objRef = _ncRef.resolve(_ncRef.to_name("iscream.Filter." + parentFilter));
125 +                    Filter filter = FilterHelper.narrow(objRef);
126 +                        _socketOut.println(filter.getHostName() + ";"
127 +                                         + filter.getUDPPort() + ";"
128 +                                         + filter.getTCPPort());
129 +                        _socketOut.flush();
130 +                }
131 +                
132 +                // confirm that all is ok
133 +                inBound = _socketIn.readLine();
134 +                if(!inBound.equals("END")) {
135 +                        // protocol error
136 +                    _socketOut.println("ERROR");
137 +                    _socketOut.flush();
138 +                    throw new IOException("protocol error - expected:END got:" + inBound);
139 +                }
140 +                else {
141 +                        // send ok
142 +                        _socketOut.println("OK");
143 +                        _socketOut.flush();
144 +                }
145 +
146              }
147              
148          } catch (Exception e) {
149 <            _logger.write(toString(), e.toString());
149 >            _logRef.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
150          }
151          
152          _socketOut.flush();
# Line 98 | Line 156 | class HostInit extends Thread {
156              _socketOut.close();
157              _socket.close();
158          } catch (IOException e) {
159 <            _logger.write(toString(), "exception on socket close");
159 >            _logRef.write(toString(), Logger.ERROR, "exception on socket close");
160          }
161 <        _logger.write(toString(), "finished");
161 >        _logRef.write(toString(), Logger.SYSMSG, "finished");
162      }
163      
164      /**
# Line 121 | Line 179 | class HostInit extends Thread {
179  
180   //---ATTRIBUTES---
181  
182 <    Configurator _configurator;
183 <    Logger _logger;
182 >    ConfigurationManager _configManager;
183 >    Logger _logRef;
184      Socket _socket;
185      BufferedReader _socketIn;
186      PrintWriter _socketOut;
187 <
187 >    NamingContextExt _ncRef;
188   //---STATIC ATTRIBUTES---
189  
190   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines