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.7 by tdb, Thu Nov 23 01:46:17 2000 UTC vs.
Revision 1.15 by tdb, Sun Jan 28 05:38:13 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;
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.*;
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 31 | 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");
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();
# Line 52 | Line 58 | class HostInit extends Thread {
58                  throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
59              }
60  
61 <            Configuration myConfig = _configManager.getConfiguration(_socket.getInetAddress().getHostName().toLowerCase());
61 >            Configuration myConfig = _configManager.getConfiguration("Host." + _socket.getInetAddress().getHostName().toLowerCase());
62              if (myConfig == null) {
63                  _socketOut.println("ERROR");
64                  throw new IOException("error in host configuration");
# Line 94 | Line 100 | class HostInit extends Thread {
100                            
101                      // get the property
102                      try {
103 <                        String returnedProperty = myConfig.getProperty(inBound);    
103 >                        String returnedProperty = myConfig.getProperty("Host."+inBound);    
104                          
105                          _socketOut.println(returnedProperty);
106                          _socketOut.flush();
# Line 105 | Line 111 | class HostInit extends Thread {
111                      }
112                      inBound = _socketIn.readLine();
113                  }
114 <                _logRef.write(toString(), Logger.SYSMSG, "configured host");
114 >                _logger.write(toString(), Logger.SYSMSG, "configured host");
115                  _socketOut.println("OK");
116                  _socketOut.flush();
117                  
# Line 120 | Line 126 | class HostInit extends Thread {
126                  else {
127                          // send info
128                          String parentFilter =  myConfig.getProperty("Host.filter");
129 <                        _logRef.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
130 <                        org.omg.CORBA.Object objRef = _ncRef.resolve(_ncRef.to_name("iscream.Filter." + parentFilter));
125 <                    Filter filter = FilterHelper.narrow(objRef);
129 >                        _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
130 >                    Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
131                          _socketOut.println(filter.getHostName() + ";"
132                                           + filter.getUDPPort() + ";"
133                                           + filter.getTCPPort());
# Line 146 | Line 151 | class HostInit extends Thread {
151              }
152              
153          } catch (Exception e) {
154 <            _logRef.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
154 >            _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
155          }
156          
157          _socketOut.flush();
# Line 156 | Line 161 | class HostInit extends Thread {
161              _socketOut.close();
162              _socket.close();
163          } catch (IOException e) {
164 <            _logRef.write(toString(), Logger.ERROR, "exception on socket close");
164 >            _logger.write(toString(), Logger.ERROR, "exception on socket close");
165          }
166 <        _logRef.write(toString(), Logger.SYSMSG, "finished");
166 >        _logger.write(toString(), Logger.SYSMSG, "finished");
167      }
168      
169      /**
170       * Overrides the {@link java.lang.Object#toString() Object.toString()}
171       * method to provide clean logging (every class should have this).
172       *
173 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
174 +     * to format the toString()
175 +     *
176       * @return the name of this class and its CVS revision
177       */
178      public String toString() {
179 <        return this.getClass().getName() + "{" + _socket.getInetAddress().getHostName()
180 <         + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
181 <        
179 >        return FormatName.getName(
180 >            _name,
181 >            getClass().getName(),
182 >            REVISION);
183      }
184  
185   //---PRIVATE METHODS---
# Line 179 | Line 188 | class HostInit extends Thread {
188  
189   //---ATTRIBUTES---
190  
191 <    ConfigurationManager _configManager;
192 <    Logger _logRef;
193 <    Socket _socket;
194 <    BufferedReader _socketIn;
195 <    PrintWriter _socketOut;
196 <    NamingContextExt _ncRef;
191 >    /**
192 >     * This holds a reference to the
193 >     * system logger that is being used.
194 >     */
195 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
196 >    
197 >    /**
198 >     * A reference to the Configuration Manager the system is using
199 >     */
200 >    private ConfigurationManager _configManager = ReferenceManager.getInstance().getCM();
201 >    
202 >    /**
203 >     * This is the friendly identifier of the
204 >     * component this class is running in.
205 >     * eg, a Filter may be called "filter1",
206 >     * If this class does not have an owning
207 >     * component,  a name from the configuration
208 >     * can be placed here.  This name could also
209 >     * be changed to null for utility classes.
210 >     */
211 >    private String _name = FilterManager.NAME;
212 >    
213 >    /**
214 >     * The socket this class uses
215 >     */
216 >    private Socket _socket;
217 >
218 >    /**
219 >     * Used for the input stream of this socket
220 >     */
221 >    private BufferedReader _socketIn;
222 >    
223 >    /**
224 >     * Used for the output stream of this socket
225 >     */
226 >    private PrintWriter _socketOut;
227 >
228   //---STATIC ATTRIBUTES---
229  
230   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines