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.19 by tdb, Tue May 29 17:02:34 2001 UTC vs.
Revision 1.22 by tdb, Sat May 18 18:16:00 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21   package uk.org.iscream.cms.server.client;
22  
# Line 10 | Line 29 | import java.io.*;
29   /**
30   * Provides a feed to the webpage system.
31   *
13 * !! There may also be need to have a Thread to grab any
14 * !! required config (groups, "nice names, etc) and dump
15 * !! that to a file.
16 *
32   * @author  $Author$
33   * @version $Id$
34   */
# Line 148 | Line 163 | public class WebFeeder extends Thread {
163              
164              // list the files and delete as appropriate
165              File alertsDir = new File(rootPath, alertSubDir);
166 <            // get all the hostnames directories
167 <            File[] contents = alertsDir.listFiles();
168 <            for(int i=0; i < contents.length; i++) {
169 <                // get a single directory from the array..
170 <                File hostdir = contents[i];
171 <                // ..and check it's a directory
172 <                if(hostdir.isDirectory()) {
173 <                    // if this is set, we clean files older than it
174 <                    long deleteFiles = -1;
175 <                    // get all the contents of that directory
176 <                    File[] hostdirContents = hostdir.listFiles();
177 <                    for(int j=0; j < hostdirContents.length; j++) {
178 <                        File alertFile = hostdirContents[j];
179 <                        // get the filename..
180 <                        String filename = alertFile.getName();
181 <                        // ..and see if it ends with OK or FINAL
182 <                        if(filename.endsWith(Alert.alertLevels[0]) ||
183 <                           filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
184 <                            // it does end with either OK or FINAL
185 <                            // ... so we can check it for deletion
186 <                            long lastModified = alertFile.lastModified();
187 <                            long age = System.currentTimeMillis() - lastModified;
188 <                            if(age > ((long) deleteOlderThan*1000)) {
189 <                                // if we're on a final heartbeat, we probably want to
190 <                                // clean up any stale alerts left behind
191 <                                // by setting this flag, we'll clean them up on leaving this loop
192 <                                if(filename.endsWith(".HB."+Alert.alertLevels[Alert.alertLevels.length-1])) {
193 <                                    // we do this so that delete files is set to the
194 <                                    // latest date of a HB.FINAL. There should only be
195 <                                    // one of them though :)
196 <                                    if(lastModified > deleteFiles) {
197 <                                        deleteFiles = lastModified;
166 >            // check it's a directory
167 >            if(alertsDir.isDirectory()) {
168 >                // get all the hostnames directories
169 >                File[] contents = alertsDir.listFiles();
170 >                for(int i=0; i < contents.length; i++) {
171 >                    // get a single directory from the array..
172 >                    File hostdir = contents[i];
173 >                    // ..and check it's a directory
174 >                    if(hostdir.isDirectory()) {
175 >                        // if this is set, we clean files older than it
176 >                        long deleteFiles = -1;
177 >                        // get all the contents of that directory
178 >                        File[] hostdirContents = hostdir.listFiles();
179 >                        for(int j=0; j < hostdirContents.length; j++) {
180 >                            File alertFile = hostdirContents[j];
181 >                            // get the filename..
182 >                            String filename = alertFile.getName();
183 >                            // ..and see if it ends with OK or FINAL
184 >                            if(filename.endsWith(Alert.alertLevels[0]) ||
185 >                               filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
186 >                                // it does end with either OK or FINAL
187 >                                // ... so we can check it for deletion
188 >                                long lastModified = alertFile.lastModified();
189 >                                long age = System.currentTimeMillis() - lastModified;
190 >                                if(age > ((long) deleteOlderThan*1000)) {
191 >                                    // if we're on a final heartbeat, we probably want to
192 >                                    // clean up any stale alerts left behind
193 >                                    // by setting this flag, we'll clean them up on leaving this loop
194 >                                    if(filename.endsWith(".HB."+Alert.alertLevels[Alert.alertLevels.length-1])) {
195 >                                        // we do this so that delete files is set to the
196 >                                        // latest date of a HB.FINAL. There should only be
197 >                                        // one of them though :)
198 >                                        if(lastModified > deleteFiles) {
199 >                                            deleteFiles = lastModified;
200 >                                        }
201                                      }
202 +                                    // it's also older than our age to delete older than
203 +                                    if(!alertFile.delete()) {
204 +                                        _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
205 +                                    }
206                                  }
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                                }
207                              }
208                          }
209 <                    }
210 <                    // cleanup stale alerts
211 <                    if(deleteFiles >= 0) {
212 <                        File[] remainingHostdirContents = hostdir.listFiles();
213 <                        for(int j=0; j < remainingHostdirContents.length; j++) {
214 <                            File alertFile = remainingHostdirContents[j];
215 <                            if(alertFile.lastModified() < deleteFiles) {
216 <                                // alert file is older than the most recent
217 <                                // FINAL Heartbeat alert.
218 <                                if(alertFile.delete()) {
219 <                                    _logger.write(this.toString(), Logger.DEBUG, "Deleted stale alert file: "+alertFile.getPath());
209 >                        // cleanup stale alerts
210 >                        if(deleteFiles >= 0) {
211 >                            File[] remainingHostdirContents = hostdir.listFiles();
212 >                            for(int j=0; j < remainingHostdirContents.length; j++) {
213 >                                File alertFile = remainingHostdirContents[j];
214 >                                if(alertFile.lastModified() < deleteFiles) {
215 >                                    // alert file is older than the most recent
216 >                                    // FINAL Heartbeat alert.
217 >                                    if(alertFile.delete()) {
218 >                                        _logger.write(this.toString(), Logger.DEBUG, "Deleted stale alert file: "+alertFile.getPath());
219 >                                    }
220 >                                    else {
221 >                                        _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'stale' alert file: "+alertFile.getPath());
222 >                                    }
223                                  }
203                                else {
204                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'stale' alert file: "+alertFile.getPath());
205                                }
224                              }
225                          }
226 <                    }
227 <                    // ---- RECAP ----
228 <                    // at this point, we have cleaned up any OK or FINAL alerts
229 <                    // that have passed our age limit. We have then cleaned up
230 <                    // any alerts older the most recent Heartbeat FINAL alert,
231 <                    // as these are probably stale. Any files left are valid and
232 <                    // active alerts. We are now in a position to remove the host
233 <                    // directory if it's empty.
234 <                    // ---------------
235 <                    // do a quick check to see if the directory is now empty
236 <                    File[] newHostdirContents = hostdir.listFiles();
237 <                    if(newHostdirContents.length == 0) {
238 <                        // it does seem to be, try and delete it
239 <                        // this will fail anyway if files still remain
240 <                        if(!hostdir.delete()) {
241 <                            _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following empty host directory: "+hostdir.getPath());
226 >                        // ---- RECAP ----
227 >                        // at this point, we have cleaned up any OK or FINAL alerts
228 >                        // that have passed our age limit. We have then cleaned up
229 >                        // any alerts older the most recent Heartbeat FINAL alert,
230 >                        // as these are probably stale. Any files left are valid and
231 >                        // active alerts. We are now in a position to remove the host
232 >                        // directory if it's empty.
233 >                        // ---------------
234 >                        // do a quick check to see if the directory is now empty
235 >                        File[] newHostdirContents = hostdir.listFiles();
236 >                        if(newHostdirContents.length == 0) {
237 >                            // it does seem to be, try and delete it
238 >                            // this will fail anyway if files still remain
239 >                            if(!hostdir.delete()) {
240 >                                _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following empty host directory: "+hostdir.getPath());
241 >                            }
242                          }
243                      }
244                  }
245 +            }
246 +            else {
247 +                _logger.write(toString(), Logger.WARNING, "IO error reading alerts directory, maybe it doesn't exist? : " +rootPath+sep+alertSubDir);
248              }
249          }
250      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines