ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/TCPReaderInit.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/TCPReaderInit.java (file contents):
Revision 1.18 by tdb, Mon Feb 12 00:35:03 2001 UTC vs.
Revision 1.23 by tdb, Tue Mar 13 16:46:13 2001 UTC

# Line 39 | Line 39 | class TCPReaderInit extends Thread {
39       * @throws IOException if something goes badly wrong
40       */
41      public TCPReaderInit(Socket socket, Queue queue) throws IOException {
42 +        // set the Thread name
43 +        setName("filter.TCPReaderInit");
44 +        
45          _socket = socket;
46          _queue = queue;
47          // setup the reader & writer
# Line 61 | Line 64 | class TCPReaderInit extends Thread {
64              String lastModified = "";
65              String inBound = "";
66              
67 <            inBound = _socketIn.readLine();
68 <            if(!inBound.equals("HEARTBEAT")) {
69 <                _socketOut.println("ERROR");
67 <                throw new IOException("protocol error - expecting:HEARTBEAT got:" + inBound);
68 <            } else {
69 <                _socketOut.println("OK");
70 <            }
67 >            // try for HEARTBEAT
68 >            getInBound("HEARTBEAT");
69 >            _socketOut.println("OK");
70              
71 <            inBound = _socketIn.readLine();
72 <            if(!inBound.equals("CONFIG")) {
73 <                _socketOut.println("ERROR");
75 <                throw new IOException("protocol error - expecting:CONFIG got:" + inBound);
76 <            } else {
77 <                _socketOut.println("OK");
78 <            }
71 >            // try for CONFIG
72 >            getInBound("CONFIG");
73 >            _socketOut.println("OK");
74              
75 <            inBound = _socketIn.readLine();
76 <            filelist = inBound;
75 >            // try for {filelist}
76 >            filelist = getInBound();
77              _socketOut.println("OK");
78              
79 <            inBound = _socketIn.readLine();
80 <            lastModified = inBound;
81 <            
79 >            // try for {lastModified}
80 >            lastModified = getInBound();
81 >            // check to see if a config update has happen
82              boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified));
88            
83              if(newConfig) {
84 +                // new config !
85                  _socketOut.println("ERROR");
86              }
87              else {
88 +                // nothing has changed
89                  _socketOut.println("OK");
90              }
91              
92 <            inBound = _socketIn.readLine();
93 <            if(!inBound.equals("ENDHEARTBEAT")) {
94 <                _socketOut.println("ERROR");
95 <                throw new IOException("protocol error - expecting:ENDHEARTBEAT got:" + inBound);
96 <            } else {
97 <                _socketOut.println("OK");
98 <            }
103 <
104 <            String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
105 <            String hostname = _socket.getInetAddress().getHostName();
92 >            // try for CONFIG
93 >            getInBound("ENDHEARTBEAT");
94 >            _socketOut.println("OK");
95 >            
96 >            // work out some information for our heartbeat packet
97 >            String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); //seconds
98 >            String hostname = _socket.getInetAddress().getHostName().toLowerCase();
99              String ipadd = _socket.getInetAddress().getHostAddress();
100              
101              // run the service checks for this host
# Line 116 | Line 109 | class TCPReaderInit extends Thread {
109              _queue.add(xml);
110              
111          } catch (Exception e) {
112 <            _logger.write(toString(), Logger.ERROR, "ERROR: " + e.getMessage());
112 >            _logger.write(toString(), Logger.ERROR, "ERROR: " + e);
113          }
114          
115          // Disconnect streams & socket
# Line 147 | Line 140 | class TCPReaderInit extends Thread {
140      }
141  
142   //---PRIVATE METHODS---
143 +
144 +    private String getInBound(String expected) throws IOException {
145 +        // grab the input
146 +        String inBound = getInBound();
147 +        // check if it's what we're expecting
148 +        if(!inBound.equals(expected)) {
149 +            throw new IOException("protocol error - expected:"+expected+" got:" + inBound);
150 +        }
151 +        // it should be ok then
152 +        return inBound;
153 +    }
154 +    
155 +    private String getInBound() throws IOException {
156 +        // grab the input
157 +        String inBound = _socketIn.readLine();
158 +        // check for null's, likely disconnection
159 +        if(inBound == null) {
160 +            throw new IOException("got null from host, maybe it died");
161 +        }
162 +        // it's a valid message it seems
163 +        return inBound;
164 +    }
165  
166   //---ACCESSOR/MUTATOR METHODS---
167  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines