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

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/WebFeeder.java (file contents):
Revision 1.17 by tdb, Thu Mar 22 18:08:38 2001 UTC vs.
Revision 1.18 by tdb, Fri Mar 23 00:44:11 2001 UTC

# Line 155 | Line 155 | public class WebFeeder extends Thread {
155                  File hostdir = contents[i];
156                  // ..and check it's a directory
157                  if(hostdir.isDirectory()) {
158 +                    // if this is set, we clean files older than it
159 +                    long deleteFiles = -1;
160                      // get all the contents of that directory
161                      File[] hostdirContents = hostdir.listFiles();
162                      for(int j=0; j < hostdirContents.length; j++) {
# Line 169 | Line 171 | public class WebFeeder extends Thread {
171                              long lastModified = alertFile.lastModified();
172                              long age = System.currentTimeMillis() - lastModified;
173                              if(age > ((long) deleteOlderThan*1000)) {
174 +                                // if we're on a final heartbeat, we probably want to
175 +                                // clean up any stale alerts left behind
176 +                                // by setting this flag, we'll clean them up on leaving this loop
177 +                                if(filename.endsWith(".HB."+Alert.alertLevels[Alert.alertLevels.length-1])) {
178 +                                    // we do this so that delete files is set to the
179 +                                    // latest date of a HB.FINAL. There should only be
180 +                                    // one of them though :)
181 +                                    if(lastModified > deleteFiles) {
182 +                                        deleteFiles = lastModified;
183 +                                    }
184 +                                }
185                                  // it's also older than our age to delete older than
186 +                                if(!alertFile.delete()) {
187 +                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
188 +                                }
189 +                            }
190 +                        }
191 +                    }
192 +                    // cleanup stale alerts
193 +                    if(deleteFiles >= 0) {
194 +                        File[] remainingHostdirContents = hostdir.listFiles();
195 +                        for(int j=0; j < remainingHostdirContents.length; j++) {
196 +                            File alertFile = remainingHostdirContents[j];
197 +                            if(alertFile.lastModified() < deleteFiles) {
198 +                                // alert file is older than the most recent
199 +                                // FINAL Heartbeat alert.
200                                  if(alertFile.delete()) {
201 <                                    // do a quick check to see if the directory is now empty
175 <                                    File[] newHostdirContents = hostdir.listFiles();
176 <                                    if(newHostdirContents.length == 0) {
177 <                                        // it does seem to be, try and delete it
178 <                                        // this will fail anyway if files still remain
179 <                                        if(!hostdir.delete()) {
180 <                                            _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following empty host directory: "+hostdir.getPath());
181 <                                        }
182 <                                    }
201 >                                    _logger.write(this.toString(), Logger.DEBUG, "Deleted stale alert file: "+alertFile.getPath());
202                                  }
203                                  else {
204 <                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
204 >                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'stale' alert file: "+alertFile.getPath());
205                                  }
206                              }
207                          }
208                      }
209 +                    // ---- RECAP ----
210 +                    // at this point, we have cleaned up any OK or FINAL alerts
211 +                    // that have passed our age limit. We have then cleaned up
212 +                    // any alerts older the most recent Heartbeat FINAL alert,
213 +                    // as these are probably stale. Any files left are valid and
214 +                    // active alerts. We are now in a position to remove the host
215 +                    // directory if it's empty.
216 +                    // ---------------
217 +                    // do a quick check to see if the directory is now empty
218 +                    File[] newHostdirContents = hostdir.listFiles();
219 +                    if(newHostdirContents.length == 0) {
220 +                        // it does seem to be, try and delete it
221 +                        // this will fail anyway if files still remain
222 +                        if(!hostdir.delete()) {
223 +                            _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following empty host directory: "+hostdir.getPath());
224 +                        }
225 +                    }
226                  }
227              }
228          }
# Line 257 | Line 293 | public class WebFeeder extends Thread {
293          File outFile;
294          // check if we're at a special "end case" (OK or FINAL)
295          if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) {
296 +            if(alert.getAttributeName().equals("Heartbeat") && alert.getLevel()==Alert.alertLevels.length-1) {
297 +                // new file is something like alert.nnnnnnnn.HB.FINAL
298 +                outFile = new File(rootPath, destFile+".HB."+Alert.alertLevels[alert.getLevel()]);
299 +            } else {
300 +                // new file is something like alert.nnnnnnnn.OK
301 +                outFile = new File(rootPath, destFile+"."+Alert.alertLevels[alert.getLevel()]);
302 +            }
303              File oldFile = new File(rootPath, destFile);
261            outFile = new File(rootPath, destFile+"."+Alert.alertLevels[alert.getLevel()]);
304              if(!oldFile.renameTo(outFile)) {
305                  _logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath());
306              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines