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.11 by tdb, Thu Mar 15 14:30:55 2001 UTC vs.
Revision 1.15 by tdb, Fri Mar 16 16:47:33 2001 UTC

# Line 36 | Line 36 | public class WebFeeder extends Thread {
36       */
37      public final int DEFAULT_AGE = 3600;
38      
39 +    /**
40 +     * The default path seperator, here for convienience
41 +     */
42 +    private final String sep = File.separator;
43 +    
44   //---STATIC METHODS---
45  
46      /**
# Line 69 | Line 74 | public class WebFeeder extends Thread {
74              // work out where things are
75              rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath");
76              alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir");
77 <            File alertsDir = new File(rootPath+"/"+alertSubDir);
77 >            File alertsDir = new File(rootPath, alertSubDir);
78              if(deleteContents(alertsDir)) {
79 <                _logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+"/"+alertSubDir);
79 >                _logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+sep+alertSubDir);
80              } else {
81 <                _logger.write(this.toString(), Logger.WARNING, "Failed to delete all files and directories from: "+rootPath+"/"+alertSubDir);
81 >                _logger.write(this.toString(), Logger.WARNING, "Failed to delete all files and directories from: "+rootPath+sep+alertSubDir);
82              }
83              // cleanup complete
84          } catch (PropertyNotFoundException e) {
# Line 141 | Line 146 | public class WebFeeder extends Thread {
146                  _logger.write(toString(), Logger.WARNING, "WebFeeder.alertDeleteOlderThan value unavailable using default of " + deleteOlderThan + " seconds");
147              }
148              
149 <            // list the files
150 <            String alertsPath = rootPath+"/"+alertSubDir;
151 <            File alertsDir = new File(alertsPath);
149 >            // list the files and delete as appropriate
150 >            File alertsDir = new File(rootPath, alertSubDir);
151 >            // get all the hostnames directories
152              File[] contents = alertsDir.listFiles();
153              for(int i=0; i < contents.length; i++) {
154 +                // get a single directory from the array..
155                  File hostdir = contents[i];
156 <                File[] hostdirContents = hostdir.listFiles();
157 <                for(int j=0; j < hostdirContents.length; j++) {
158 <                    File alertFile = hostdirContents[j];
159 <                    String filename = alertFile.getName();
160 <                    if(filename.endsWith(Alert.alertLevels[0]) ||
161 <                       filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
162 <                        // it ends with either OK or FINAL
163 <                        // ... so we can check it for deletion
164 <                        long lastModified = alertFile.lastModified();
165 <                        long age = System.currentTimeMillis() - lastModified;
166 <                        if(age > ((long) deleteOlderThan*1000)) {
167 <                            // it's also older than our age to delete older than
168 <                            if(!alertFile.delete()) {
169 <                                _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
156 >                // ..and check it's a directory
157 >                if(hostdir.isDirectory()) {
158 >                    // get all the contents of that directory
159 >                    File[] hostdirContents = hostdir.listFiles();
160 >                    for(int j=0; j < hostdirContents.length; j++) {
161 >                        File alertFile = hostdirContents[j];
162 >                        // get the filename..
163 >                        String filename = alertFile.getName();
164 >                        // ..and see if it ends with OK or FINAL
165 >                        if(filename.endsWith(Alert.alertLevels[0]) ||
166 >                           filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) {
167 >                            // it does end with either OK or FINAL
168 >                            // ... so we can check it for deletion
169 >                            long lastModified = alertFile.lastModified();
170 >                            long age = System.currentTimeMillis() - lastModified;
171 >                            if(age > ((long) deleteOlderThan*1000)) {
172 >                                // it's also older than our age to delete older than
173 >                                if(!alertFile.delete()) {
174 >                                    _logger.write(this.toString(), Logger.WARNING, "Failed to delete the following 'old' alert file: "+alertFile.getPath());
175 >                                }
176                              }
177                          }
178                      }
179                  }
180              }
169            // check through, deleting those passed the age barrier
181          }
182      }
183      
# Line 200 | Line 211 | public class WebFeeder extends Thread {
211          String data = packet.printAll();
212          String hostname = packet.getParam("packet.attributes.machine_name");
213          // set paths
214 <        String destDir = rootPath+"/"+latestSubDir+"/"+hostname;
215 <        File outDir = new File(destDir);
205 <        String destFile = destDir+"/"+latestFileName;
206 <        File outFile = new File(destFile);
214 >        File outDir = new File(rootPath, latestSubDir+sep+hostname);
215 >        File outFile = new File(rootPath, latestSubDir+sep+hostname+sep+latestFileName);
216          // write the data out
217          writeData(outDir, outFile, data);
218      }
# Line 232 | Line 241 | public class WebFeeder extends Thread {
241          String data = alert.printAll();
242          String hostname = alert.getSource();
243          // set paths
244 <        String destDir = rootPath+"/"+alertSubDir+"/"+hostname;
245 <        File outDir = new File(destDir);
237 <        String destFile = destDir+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
244 >        File outDir = new File(rootPath, alertSubDir+sep+hostname);
245 >        String destFile = alertSubDir+sep+hostname+sep+alertFileName+"."+String.valueOf(alert.getInitialAlertTime());
246          File outFile;
247          // check if we're at a special "end case" (OK or FINAL)
248          if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) {
249 <            File oldFile = new File(destFile);
250 <            outFile = new File(destFile+"."+Alert.alertLevels[alert.getLevel()]);
249 >            File oldFile = new File(rootPath, destFile);
250 >            outFile = new File(rootPath, destFile+"."+Alert.alertLevels[alert.getLevel()]);
251              if(!oldFile.renameTo(outFile)) {
252                  _logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath());
253              }
254          } else {
255 <            outFile = new File(destFile);
255 >            outFile = new File(rootPath, destFile);
256          }
257          // write the data out
258          writeData(outDir, outFile, data);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines