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.11 by tdb, Thu Dec 7 00:02:17 2000 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.filtermanager;
3  
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.core.*;
6 + import uk.ac.ukc.iscream.filter.*;
7 + import uk.ac.ukc.iscream.util.*;
8   import java.net.Socket;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8 import java.io.IOException;
9   import java.io.*;
10  
11   /**
12 < * <ONE LINE DESCRIPTION>
13 < * <DETAILED DESCRIPTION>
12 > * Handles setting up a host.
13   *
14   * @author  $Author$
15   * @version $Id$
# Line 28 | Line 27 | class HostInit extends Thread {
27  
28   //---CONSTRUCTORS---
29  
30 <    public HostInit(Socket socket, Configurator configurator, Logger logger) throws IOException {
32 <        _configurator = configurator;
33 <        _logger = logger;
30 >    public HostInit(Socket socket) throws IOException {
31          _socket = socket;
32          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
33          _socketOut = new PrintWriter(_socket.getOutputStream());
34 <        _logger.write(toString(), "created");
34 >        _logger.write(toString(), Logger.SYSINIT, "created");
35      }
36      
37   //---PUBLIC METHODS---
# Line 45 | Line 42 | class HostInit extends Thread {
42              if (!inBound.equals("STARTCONFIG")) {
43                  _socketOut.println("ERROR");
44                  _socketOut.flush();
45 <                throw new IOException("Protocol Error");
45 >                throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
46              }
47  
48 <            Configuration myConfig = _configurator.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase());
48 >            Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
49              if (myConfig == null) {
50                  _socketOut.println("ERROR");
51 <                throw new IOException("No Configuration File For Host");
51 >                throw new IOException("error in host configuration");
52              } else {
53                  _socketOut.println("OK");
54                  _socketOut.flush();
55                  
56                  // get lastmodified
57                  inBound = _socketIn.readLine();
58 <                while(!inBound.equals("LASTMODIFIED")) {
58 >                if(!inBound.equals("LASTMODIFIED")) {
59 >                        // protocol error
60                      _socketOut.println("ERROR");
61                      _socketOut.flush();
62 +                    throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
63                  }
64 <                _socketOut.println(myConfig.getLastModified());
65 <                _socketOut.flush();
64 >                else {
65 >                        // send info
66 >                        _socketOut.println(myConfig.getLastModified());
67 >                        _socketOut.flush();
68 >                }
69                  
70 +                // 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                  // get properties
85                  inBound = _socketIn.readLine();
86                  while(!inBound.equals("ENDCONFIG")) {
87                            
88                      // get the property
89                      try {
90 <                        String returnedProperty = myConfig.getProperty(inBound);    
90 >                        String returnedProperty = myConfig.getProperty("Host."+inBound);    
91                          
92                          _socketOut.println(returnedProperty);
93                          _socketOut.flush();
# Line 82 | Line 98 | class HostInit extends Thread {
98                      }
99                      inBound = _socketIn.readLine();
100                  }
101 <                _logger.write(toString(), "configured host");
101 >                _logger.write(toString(), Logger.SYSMSG, "configured host");
102                  _socketOut.println("OK");
103                  _socketOut.flush();
104 +                
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 +                        _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
117 +                    Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
118 +                        _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              }
139              
140          } catch (Exception e) {
141 <            _logger.write(toString(), e.toString());
141 >            _logger.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
142          }
143          
144          _socketOut.flush();
# Line 98 | Line 148 | class HostInit extends Thread {
148              _socketOut.close();
149              _socket.close();
150          } catch (IOException e) {
151 <            _logger.write(toString(), "exception on socket close");
151 >            _logger.write(toString(), Logger.ERROR, "exception on socket close");
152          }
153 <        _logger.write(toString(), "finished");
153 >        _logger.write(toString(), Logger.SYSMSG, "finished");
154      }
155      
156      /**
# Line 121 | Line 171 | class HostInit extends Thread {
171  
172   //---ATTRIBUTES---
173  
174 <    Configurator _configurator;
175 <    Logger _logger;
174 >    /**
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      Socket _socket;
185      BufferedReader _socketIn;
186      PrintWriter _socketOut;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines