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.18 by tdb, Wed Feb 28 10:27:54 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  
12   /**
# Line 29 | Line 30 | class HostInit extends Thread {
30  
31   //---CONSTRUCTORS---
32  
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 +        // setup reader & writer
41          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
42 <        _socketOut = new PrintWriter(_socket.getOutputStream());
42 >        _socketOut = new PrintWriter(_socket.getOutputStream(), true);
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();
55              if (!inBound.equals("STARTCONFIG")) {
56                  _socketOut.println("ERROR");
46                _socketOut.flush();
57                  throw new IOException("protocol error - expected:STARTCONFIG got:" + inBound);
58              }
59  
# Line 53 | Line 63 | class HostInit extends Thread {
63                  throw new IOException("error in host configuration");
64              } else {
65                  _socketOut.println("OK");
56                _socketOut.flush();
66                  
67                  // get lastmodified
68                  inBound = _socketIn.readLine();
69                  if(!inBound.equals("LASTMODIFIED")) {
70                          // protocol error
71                      _socketOut.println("ERROR");
63                    _socketOut.flush();
72                      throw new IOException("protocol error - expected:LASTMODIFIED got:" + inBound);
73                  }
74                  else {
75                          // send info
76                          _socketOut.println(myConfig.getLastModified());
69                        _socketOut.flush();
77                  }
78                  
79                  // get config fileList
# Line 74 | Line 81 | class HostInit extends Thread {
81                  if(!inBound.equals("FILELIST")) {
82                          // protocol error
83                      _socketOut.println("ERROR");
77                    _socketOut.flush();
84                      throw new IOException("protocol error - expected:FILELIST got:" + inBound);
85                  }
86                  else {
87                          // send info
88                          _socketOut.println(myConfig.getFileList());
83                        _socketOut.flush();
89                  }
90 <
90 >                
91 >                // send the FQDN to the host
92 >                inBound = _socketIn.readLine();
93 >                if(!inBound.equals("FQDN")) {
94 >                        // protocol error
95 >                    _socketOut.println("ERROR");
96 >                    throw new IOException("protocol error - expected:FQDN got:" + inBound);
97 >                }
98 >                else {
99 >                    try {
100 >                        // try to send the fqdn to the host
101 >                            _socketOut.println(InetAddress.getLocalHost().getHostName());
102 >                        }
103 >                        catch(UnknownHostException e) {
104 >                            // we failed for some reason
105 >                            _socketOut.println("ERROR");
106 >                        }
107 >                }
108 >                
109                  // get properties
110                  inBound = _socketIn.readLine();
111                  while(!inBound.equals("ENDCONFIG")) {
# Line 92 | Line 115 | class HostInit extends Thread {
115                          String returnedProperty = myConfig.getProperty("Host."+inBound);    
116                          
117                          _socketOut.println(returnedProperty);
95                        _socketOut.flush();
118      
119                      } catch (org.omg.CORBA.MARSHAL e) {
120                          _socketOut.println("ERROR");
99                        _socketOut.flush();
121                      }
122                      inBound = _socketIn.readLine();
123                  }
124                  _logger.write(toString(), Logger.SYSMSG, "configured host");
125                  _socketOut.println("OK");
105                _socketOut.flush();
126                  
127                  // get filter reference
128                  inBound = _socketIn.readLine();
129                  if(!inBound.equals("FILTER")) {
130                          // protocol error
131                      _socketOut.println("ERROR");
112                    _socketOut.flush();
132                      throw new IOException("protocol error - expected:FILTER got:" + inBound);
133                  }
134                  else {
# Line 120 | Line 139 | class HostInit extends Thread {
139                          _socketOut.println(filter.getHostName() + ";"
140                                           + filter.getUDPPort() + ";"
141                                           + filter.getTCPPort());
123                        _socketOut.flush();
142                  }
143                  
144                  // confirm that all is ok
# Line 128 | Line 146 | class HostInit extends Thread {
146                  if(!inBound.equals("END")) {
147                          // protocol error
148                      _socketOut.println("ERROR");
131                    _socketOut.flush();
149                      throw new IOException("protocol error - expected:END got:" + inBound);
150                  }
151                  else {
152                          // send ok
153                          _socketOut.println("OK");
137                        _socketOut.flush();
154                  }
155  
156              }
157              
158          } catch (Exception e) {
159 <            _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
159 >            _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
160          }
161          
162          _socketOut.flush();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines