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.5 by tdb, Thu Nov 16 18:14:05 2000 UTC vs.
Revision 1.14 by tdb, Thu Jan 18 23:15:09 2001 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 uk.ac.ukc.iscream.componentmanager.*;
9   import java.net.Socket;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8 import java.io.IOException;
10   import java.io.*;
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 28 | Line 30 | class HostInit extends Thread {
30  
31   //---CONSTRUCTORS---
32  
33 <    public HostInit(Socket socket, Configurator configurator, Logger logger) throws IOException {
32 <        _configurator = configurator;
33 <        _logger = logger;
33 >    public HostInit(Socket socket) throws IOException {
34          _socket = socket;
35          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
36          _socketOut = new PrintWriter(_socket.getOutputStream());
# Line 45 | Line 45 | class HostInit extends Thread {
45              if (!inBound.equals("STARTCONFIG")) {
46                  _socketOut.println("ERROR");
47                  _socketOut.flush();
48 <                throw new IOException("Protocol Error");
48 >                throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
49              }
50  
51 <            Configuration myConfig = _configurator.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase());
51 >            Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
52              if (myConfig == null) {
53                  _socketOut.println("ERROR");
54 <                throw new IOException("No Configuration File For Host");
54 >                throw new IOException("error in host configuration");
55              } else {
56                  _socketOut.println("OK");
57                  _socketOut.flush();
# Line 62 | Line 62 | class HostInit extends Thread {
62                          // protocol error
63                      _socketOut.println("ERROR");
64                      _socketOut.flush();
65 <                    throw new IOException("Protocol Error");
65 >                    throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
66                  }
67                  else {
68                          // send info
# Line 70 | Line 70 | class HostInit extends Thread {
70                          _socketOut.flush();
71                  }
72                  
73 +                // 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                  // get properties
88                  inBound = _socketIn.readLine();
89                  while(!inBound.equals("ENDCONFIG")) {
90                            
91                      // get the property
92                      try {
93 <                        String returnedProperty = myConfig.getProperty(inBound);    
93 >                        String returnedProperty = myConfig.getProperty("Host."+inBound);    
94                          
95                          _socketOut.println(returnedProperty);
96                          _socketOut.flush();
# Line 90 | Line 104 | class HostInit extends Thread {
104                  _logger.write(toString(), Logger.SYSMSG, "configured host");
105                  _socketOut.println("OK");
106                  _socketOut.flush();
107 +                
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 +                        _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
120 +                    Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
121 +                        _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              }
142              
143          } catch (Exception e) {
144 <            _logger.write(toString(), Logger.ERROR, e.toString());
144 >            _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
145          }
146          
147          _socketOut.flush();
# Line 112 | Line 160 | class HostInit extends Thread {
160       * Overrides the {@link java.lang.Object#toString() Object.toString()}
161       * method to provide clean logging (every class should have this).
162       *
163 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
164 +     * to format the toString()
165 +     *
166       * @return the name of this class and its CVS revision
167       */
168      public String toString() {
169 <        return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
170 <         + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
171 <        
169 >        return FormatName.getName(
170 >            _name,
171 >            getClass().getName(),
172 >            REVISION);
173      }
174  
175   //---PRIVATE METHODS---
# Line 126 | Line 178 | class HostInit extends Thread {
178  
179   //---ATTRIBUTES---
180  
181 <    Configurator _configurator;
182 <    Logger _logger;
183 <    Socket _socket;
184 <    BufferedReader _socketIn;
185 <    PrintWriter _socketOut;
181 >    /**
182 >     * This holds a reference to the
183 >     * system logger that is being used.
184 >     */
185 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
186 >    
187 >    /**
188 >     * A reference to the Configuration Manager the system is using
189 >     */
190 >    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 >    
213 >    /**
214 >     * Used for the output stream of this socket
215 >     */
216 >    private PrintWriter _socketOut;
217  
218   //---STATIC ATTRIBUTES---
219  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines