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.13 by ajm, Tue Dec 12 20:43:21 2000 UTC vs.
Revision 1.25 by tdb, Tue Mar 13 02:19:47 2001 UTC

# Line 5 | Line 5 | package uk.ac.ukc.iscream.filtermanager;
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;
8 > import uk.ac.ukc.iscream.componentmanager.*;
9 > import java.net.*;
10   import java.io.*;
11 + import java.util.*;
12  
13   /**
14   * Handles setting up a host.
# Line 29 | Line 31 | class HostInit extends Thread {
31  
32   //---CONSTRUCTORS---
33  
34 +    /**
35 +     * Construct a new HostInit.
36 +     *
37 +     * @param socket The socket to which the host is connected
38 +     */
39      public HostInit(Socket socket) throws IOException {
40 +        // set the Thread name
41 +        setName("filtermanager.HostInit");
42 +        
43          _socket = socket;
44 +        // setup reader & writer
45          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
46 <        _socketOut = new PrintWriter(_socket.getOutputStream());
46 >        _socketOut = new PrintWriter(_socket.getOutputStream(), true);
47          _logger.write(toString(), Logger.SYSINIT, "created");
48      }
49      
50   //---PUBLIC METHODS---
51  
52 +    /**
53 +     * Main method in this class, which handles communicating with
54 +     * the host to determine it's setup.
55 +     */
56      public void run() {
57          try {
58              String inBound = _socketIn.readLine();
59              if (!inBound.equals("STARTCONFIG")) {
60                  _socketOut.println("ERROR");
46                _socketOut.flush();
61                  throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
62              }
63  
# Line 53 | Line 67 | class HostInit extends Thread {
67                  throw new IOException("error in host configuration");
68              } else {
69                  _socketOut.println("OK");
56                _socketOut.flush();
70                  
71                  // get lastmodified
72                  inBound = _socketIn.readLine();
73                  if(!inBound.equals("LASTMODIFIED")) {
74                          // protocol error
75                      _socketOut.println("ERROR");
63                    _socketOut.flush();
76                      throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
77                  }
78                  else {
79                          // send info
80                          _socketOut.println(myConfig.getLastModified());
69                        _socketOut.flush();
81                  }
82                  
83                  // get config fileList
# Line 74 | Line 85 | class HostInit extends Thread {
85                  if(!inBound.equals("FILELIST")) {
86                          // protocol error
87                      _socketOut.println("ERROR");
77                    _socketOut.flush();
88                      throw new IOException("protocol error - expected:FILELIST got:" + inBound);
89                  }
90                  else {
91                          // send info
92                          _socketOut.println(myConfig.getFileList());
83                        _socketOut.flush();
93                  }
94 <
94 >                
95 >                // send the FQDN to the host
96 >                inBound = _socketIn.readLine();
97 >                if(!inBound.equals("FQDN")) {
98 >                        // protocol error
99 >                    _socketOut.println("ERROR");
100 >                    throw new IOException("protocol error - expected:FQDN got:" + inBound);
101 >                }
102 >                else {
103 >                    // send the fqdn (of the host) to the host
104 >                    _socketOut.println(_socket.getInetAddress().getHostName().toLowerCase());
105 >                }
106 >                
107                  // get properties
108                  inBound = _socketIn.readLine();
109                  while(!inBound.equals("ENDCONFIG")) {
# Line 92 | Line 113 | class HostInit extends Thread {
113                          String returnedProperty = myConfig.getProperty("Host."+inBound);    
114                          
115                          _socketOut.println(returnedProperty);
95                        _socketOut.flush();
116      
117                      } catch (org.omg.CORBA.MARSHAL e) {
118                          _socketOut.println("ERROR");
99                        _socketOut.flush();
119                      }
120                      inBound = _socketIn.readLine();
121                  }
122                  _logger.write(toString(), Logger.SYSMSG, "configured host");
123                  _socketOut.println("OK");
105                _socketOut.flush();
124                  
125                  // get filter reference
126                  inBound = _socketIn.readLine();
127                  if(!inBound.equals("FILTER")) {
128                          // protocol error
129                      _socketOut.println("ERROR");
112                    _socketOut.flush();
130                      throw new IOException("protocol error - expected:FILTER got:" + inBound);
131                  }
132                  else {
133                          // send info
134 <                        String parentFilter =  myConfig.getProperty("Host.filter");
135 <                        _logger.write(toString(), Logger.DEBUG, " looking for parent - " + parentFilter);
136 <                    Filter filter = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + parentFilter));
137 <                        _socketOut.println(filter.getHostName() + ";"
138 <                                         + filter.getUDPPort() + ";"
139 <                                         + filter.getTCPPort());
140 <                        _socketOut.flush();
134 >                        String filterList = myConfig.getProperty("Host.filter");
135 >                        Filter filterRef = null;
136 >                        String filter = null;
137 >                        StringTokenizer st = new StringTokenizer(filterList, ";");
138 >                    while (filterRef==null && st.hasMoreTokens()) {
139 >                        filter = st.nextToken();
140 >                        _logger.write(toString(), Logger.DEBUG, " looking for filter- " + filter);
141 >                        try {
142 >                            filterRef = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + filter));
143 >                        } catch (ComponentCORBAException e) {
144 >                            _logger.write(toString(), Logger.DEBUG, " unable to find filter- " + filter);
145 >                        }
146 >                    }
147 >                        
148 >                        // hopefully we found a filter
149 >                    if(filterRef != null) {
150 >                        _logger.write(toString(), Logger.DEBUG, " found filter- " + filter);
151 >                        // tell the host about it...
152 >                            _socketOut.println(filterRef.getHostName() + ";"
153 >                                             + filterRef.getUDPPort() + ";"
154 >                                             + filterRef.getTCPPort());
155 >                        }
156 >                        else {
157 >                            // ...or throw a wobbly (and tell the host!)
158 >                            _socketOut.println("ERROR");
159 >                            throw new IOException("unable to find filter for host");
160 >                        }
161                  }
162                  
163                  // confirm that all is ok
# Line 128 | Line 165 | class HostInit extends Thread {
165                  if(!inBound.equals("END")) {
166                          // protocol error
167                      _socketOut.println("ERROR");
131                    _socketOut.flush();
168                      throw new IOException("protocol error - expected:END got:" + inBound);
169                  }
170                  else {
171                          // send ok
172                          _socketOut.println("OK");
137                        _socketOut.flush();
173                  }
174  
175              }
176              
177          } catch (Exception e) {
178 <            _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
178 >            _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
179          }
180          
181          _socketOut.flush();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines