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.21 by tdb, Tue Mar 13 02:19:46 2001 UTC vs.
Revision 1.22 by tdb, Tue Mar 13 16:25:57 2001 UTC

# Line 64 | 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");
70 <                throw new IOException("protocol error - expecting:HEARTBEAT got:" + inBound);
71 <            } else {
72 <                _socketOut.println("OK");
73 <            }
67 >            // try for HEARTBEAT
68 >            getInBound("STARTCONFIG");
69 >            _socketOut.println("OK");
70              
71 <            inBound = _socketIn.readLine();
72 <            if(!inBound.equals("CONFIG")) {
73 <                _socketOut.println("ERROR");
78 <                throw new IOException("protocol error - expecting:CONFIG got:" + inBound);
79 <            } else {
80 <                _socketOut.println("OK");
81 <            }
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));
91            
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");
105 <            }
106 <
107 <            String date = new Long(System.currentTimeMillis()/((long) 1000)).toString();
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              
# Line 150 | 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