You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/11/22 11:20:51 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/store FilesystemQueueObject.java FilesystemStore.java StoreJanitor.java

cziegeler    01/11/22 02:20:51

  Modified:    src/org/apache/cocoon/components/store Tag: cocoon_20_branch
                        FilesystemQueueObject.java FilesystemStore.java
                        StoreJanitor.java
  Log:
  Finished cleanup code
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +17 -17    xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemQueueObject.java
  
  Index: FilesystemQueueObject.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemQueueObject.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- FilesystemQueueObject.java	2001/11/06 09:55:35	1.1.2.1
  +++ FilesystemQueueObject.java	2001/11/22 10:20:51	1.1.2.2
  @@ -12,26 +12,26 @@
    *
    * @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
    */
  -public class FilesystemQueueObject implements Comparable {
  -  private Object object;
  -  private Object key;
  +public final class FilesystemQueueObject
  +implements Comparable {
   
  -  public FilesystemQueueObject (Object key, Object object) {
  -    this.object = object;
  -    this.key = key;
  -  }
  +    private Object object;
  +    private Object key;
   
  -  public FilesystemQueueObject() {}
  +    public FilesystemQueueObject (Object key, Object object) {
  +        this.object = object;
  +        this.key = key;
  +    }
   
  -  public Object getKey() {
  -    return this.key;
  -  }
  +    public Object getKey() {
  +        return this.key;
  +    }
   
  -  public Object getObject() {
  -    return this.object;
  -  }
  +    public Object getObject() {
  +        return this.object;
  +    }
   
  -  public int compareTo(Object o) {
  -    return 0;
  -  }
  +    public int compareTo(Object o) {
  +        return 0;
  +    }
   }
  
  
  
  1.1.1.1.2.10 +204 -198  xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemStore.java
  
  Index: FilesystemStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemStore.java,v
  retrieving revision 1.1.1.1.2.9
  retrieving revision 1.1.1.1.2.10
  diff -u -r1.1.1.1.2.9 -r1.1.1.1.2.10
  --- FilesystemStore.java	2001/11/22 10:02:04	1.1.1.1.2.9
  +++ FilesystemStore.java	2001/11/22 10:20:51	1.1.1.1.2.10
  @@ -19,7 +19,7 @@
   import java.io.IOException;
   import java.util.Enumeration;
   
  -public class FilesystemStore
  +public final class FilesystemStore
   extends AbstractLoggable
   implements Contextualizable, Store, ThreadSafe {
   
  @@ -30,11 +30,13 @@
       /**
        * Sets the repository's location
        */
  -    public void setDirectory(String directory) throws IOException {
  +    public void setDirectory(final String directory)
  +    throws IOException {
           this.setDirectory(new File(directory));
       }
   
  -    public void contextualize(Context context) throws ContextException {
  +    public void contextualize(final Context context)
  +    throws ContextException {
           try {
               setDirectory((File) context.get(Constants.CONTEXT_WORK_DIR));
           } catch (Exception e) {
  @@ -42,205 +44,209 @@
           }
       }
   
  -  /**
  -   * Sets the repository's location
  -   */
  -  public void setDirectory(File directory) throws IOException {
  -    this.directoryFile = directory;
  -
  -    /* Save directory path prefix */
  -    this.directoryPath = IOUtils.getFullFilename(this.directoryFile);
  -    this.directoryPath += File.separator;
  -
  -    /* Does directory exist? */
  -    if (!this.directoryFile.exists()) {
  -      /* Create it anew */
  -      if (!this.directoryFile.mkdir()) {
  -        throw new IOException(
  -      "Error creating store directory '" + this.directoryPath + "': "
  -    );
  -      }
  -    }
  -
  -    /* Is given file actually a directory? */
  -    if (!this.directoryFile.isDirectory()) {
  -      throw new IOException("'" + this.directoryPath + "' is not a directory");
  -    }
  -
  -    /* Is directory readable and writable? */
  -    if (!(this.directoryFile.canRead() && this.directoryFile.canWrite())) {
  -      throw new IOException(
  -        "Directory '" + this.directoryPath + "' is not readable/writable"
  -      );
  -    }
  -  }
  -
  -  /**
  -   * Returns the repository's full pathname
  -   */
  -  public String getDirectoryPath() {
  -    return this.directoryPath;
  -  }
  -
  -  /**
  -   * Get the file associated with the given unique key name.
  -   */
  -  public Object get(Object key) {
  -    getLogger().debug("FilesystemStore get(): Get file with key: " + key.toString());
  -    File file = fileFromKey(key);
  -
  -    if (file != null && file.exists()) {
  -      getLogger().debug("FilesystemStore get(): Found file with key: " + key.toString());
  -      return file;
  -    }
  -    return null;
  -  }
  -
  -  /**
  -   * Store the given object in a persistent state.
  -   * 1) Null values generate empty directories.
  -   * 2) String values are dumped to text files
  -   * 3) Object values are serialized
  -   */
  -  public void store(Object key, Object value) throws IOException {
  -      File file = fileFromKey(key);
  -
  -      /* Create subdirectories as needed */
  -      File parent = file.getParentFile();
  -      if (parent != null) {
  -        parent.mkdirs();
  -      }
  -
  -      /* Store object as file */
  -      if (value == null) { /* Directory */
  -        if (file.exists()) {
  -          if (!file.delete()) { /* FAILURE */
  -           getLogger().error("File cannot be deleted: " + file.toString());
  -           return;
  -          }
  -        }
  -
  -        file.mkdir();
  -      } else if (value instanceof String) { /* Text file */
  -        IOUtils.serializeString(file, (String) value);
  -      } else { /* Serialized Object */
  -        IOUtils.serializeObject(file, value);
  -      }
  -  }
  -
  -  /**
  -   * Holds the given object in a volatile state.
  -   */
  -  public void hold(Object key, Object value) throws IOException {
  -    this.store(key, value);
  -    File file = (File) this.get(key);
  -    if (file != null) {
  -      file.deleteOnExit();
  -    }
  -  }
  -
  -  /**
  -   * Remove the object associated to the given key.
  -   */
  -  public void remove(Object key) {
  -    File file = fileFromKey(key);
  -    if (file != null) {
  -      file.delete();
  -    }
  -  }
  -
  -  /**
  -   * Indicates if the given key is associated to a contained object.
  -   */
  -  public boolean containsKey(Object key) {
  -    File file = fileFromKey(key);
  -    if (file == null) {
  -      return false;
  -    }
  -    return file.exists();
  -  }
  -
  -  /**
  -   * Returns the list of stored files as an Enumeration of Files
  -   */
  -  public Enumeration keys() {
  -    FSEnumeration enum = new FSEnumeration();
  -    this.addKeys(enum, this.directoryFile);
  -    return enum;
  -  }
  -
  -  protected void addKeys(FSEnumeration enum,
  -                         File  directory) {
  -      final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 1;
  -      final File[] files = directory.listFiles();
  -      for(int i=0; i<files.length; i++) {
  -          if (files[i].isDirectory() == true) {
  -              this.addKeys(enum, files[i]);
  -          } else {
  -              enum.add(files[i].getAbsolutePath().substring(subStringBegin));
  -          }
  -      }
  -  }
  -
  -  final class FSEnumeration implements Enumeration {
  -      private String[] array;
  -      private int      index;
  -      private int      length;
  -
  -      FSEnumeration() {
  -          this.array = new String[16];
  -          this.length = 0;
  -          this.index = 0;
  -      }
  -
  -      public void add(String key) {
  -          if (this.length == array.length) {
  -              String[] newarray = new String[this.length + 16];
  -              System.arraycopy(this.array, 0, newarray, 0, this.array.length);
  -              this.array = newarray;
  -          }
  -          this.array[this.length] = key;
  -          this.length++;
  -      }
  -
  -      public boolean hasMoreElements() {
  -          return (this.index < this.length);
  -      }
  -
  -      public Object nextElement() {
  -          if (this.hasMoreElements() == true) {
  -              this.index++;
  -              return this.array[index-1];
  -          }
  -          return null;
  -      }
  -  }
  -
  -  /* Utility Methods*/
  -  protected File fileFromKey(Object key) {
  -    String name = key.toString();
  -    return IOUtils.createFile(this.directoryFile, name);
  -  }
  -
  -  public String getString(Object key) throws IOException {
  -    File file = (File) this.get(key);
  -    if (file != null) {
  -      return IOUtils.deserializeString(file);
  +    /**
  +     * Sets the repository's location
  +     */
  +    public void setDirectory(final File directory)
  +    throws IOException {
  +        this.directoryFile = directory;
  +
  +        /* Save directory path prefix */
  +        this.directoryPath = IOUtils.getFullFilename(this.directoryFile);
  +        this.directoryPath += File.separator;
  +
  +        /* Does directory exist? */
  +        if (!this.directoryFile.exists()) {
  +            /* Create it anew */
  +            if (!this.directoryFile.mkdir()) {
  +                throw new IOException(
  +                "Error creating store directory '" + this.directoryPath + "': ");
  +            }
  +        }
  +
  +        /* Is given file actually a directory? */
  +        if (!this.directoryFile.isDirectory()) {
  +            throw new IOException("'" + this.directoryPath + "' is not a directory");
  +        }
  +
  +        /* Is directory readable and writable? */
  +        if (!(this.directoryFile.canRead() && this.directoryFile.canWrite())) {
  +            throw new IOException(
  +                "Directory '" + this.directoryPath + "' is not readable/writable"
  +            );
  +        }
       }
   
  -    return null;
  -  }
  +    /**
  +     * Returns the repository's full pathname
  +     */
  +    public String getDirectoryPath() {
  +        return this.directoryPath;
  +    }
   
  -  public void free() {}
  +    /**
  +     * Get the file associated with the given unique key name.
  +     */
  +    public Object get(final Object key) {
  +        if (this.getLogger().isDebugEnabled() == true)
  +            getLogger().debug("FilesystemStore get(): Get file with key: " + key.toString());
  +        final File file = fileFromKey(key);
  +
  +        if (file != null && file.exists()) {
  +            if (this.getLogger().isDebugEnabled() == true)
  +                getLogger().debug("FilesystemStore get(): Found file with key: " + key.toString());
  +            return file;
  +        }
  +        return null;
  +    }
   
  -  public Object getObject(Object key)
  -    throws IOException, ClassNotFoundException
  -  {
  -    File file = (File) this.get(key);
  -    if (file != null) {
  -      return IOUtils.deserializeObject(file);
  +    /**
  +     * Store the given object in a persistent state.
  +     * 1) Null values generate empty directories.
  +     * 2) String values are dumped to text files
  +     * 3) Object values are serialized
  +     */
  +    public void store(final Object key, final Object value)
  +    throws IOException {
  +        final File file = fileFromKey(key);
  +
  +        /* Create subdirectories as needed */
  +        final File parent = file.getParentFile();
  +        if (parent != null) {
  +            parent.mkdirs();
  +        }
  +
  +        /* Store object as file */
  +        if (value == null) { /* Directory */
  +            if (file.exists()) {
  +                if (!file.delete()) { /* FAILURE */
  +                    getLogger().error("File cannot be deleted: " + file.toString());
  +                    return;
  +                }
  +            }
  +
  +            file.mkdir();
  +        } else if (value instanceof String) { /* Text file */
  +            IOUtils.serializeString(file, (String) value);
  +        } else { /* Serialized Object */
  +            IOUtils.serializeObject(file, value);
  +        }
  +    }
  +
  +    /**
  +     * Holds the given object in a volatile state.
  +     */
  +    public void hold(final Object key, final Object value)
  +    throws IOException {
  +        this.store(key, value);
  +        final File file = (File) this.get(key);
  +        if (file != null) {
  +          file.deleteOnExit();
  +        }
  +    }
  +
  +    /**
  +     * Remove the object associated to the given key.
  +     */
  +    public void remove(final Object key) {
  +        final File file = fileFromKey(key);
  +        if (file != null) {
  +            file.delete();
  +        }
       }
   
  -    return null;
  -  }
  +    /**
  +     * Indicates if the given key is associated to a contained object.
  +     */
  +    public boolean containsKey(final Object key) {
  +        final File file = fileFromKey(key);
  +        if (file == null) {
  +            return false;
  +        }
  +        return file.exists();
  +    }
  +
  +    /**
  +     * Returns the list of stored files as an Enumeration of Files
  +     */
  +   public Enumeration keys() {
  +        final FSEnumeration enum = new FSEnumeration();
  +        this.addKeys(enum, this.directoryFile);
  +        return enum;
  +    }
  +
  +    protected void addKeys(FSEnumeration enum,
  +                           File  directory) {
  +        final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 1;
  +        final File[] files = directory.listFiles();
  +        for(int i=0; i<files.length; i++) {
  +            if (files[i].isDirectory() == true) {
  +                this.addKeys(enum, files[i]);
  +            } else {
  +                enum.add(files[i].getAbsolutePath().substring(subStringBegin));
  +            }
  +        }
  +    }
  +
  +    final class FSEnumeration implements Enumeration {
  +        private String[] array;
  +        private int      index;
  +        private int      length;
  +
  +        FSEnumeration() {
  +            this.array = new String[16];
  +            this.length = 0;
  +            this.index = 0;
  +        }
  +
  +        public void add(String key) {
  +            if (this.length == array.length) {
  +                String[] newarray = new String[this.length + 16];
  +                System.arraycopy(this.array, 0, newarray, 0, this.array.length);
  +                this.array = newarray;
  +            }
  +            this.array[this.length] = key;
  +            this.length++;
  +        }
  +
  +        public boolean hasMoreElements() {
  +            return (this.index < this.length);
  +        }
  +
  +        public Object nextElement() {
  +            if (this.hasMoreElements() == true) {
  +                this.index++;
  +                return this.array[index-1];
  +            }
  +            return null;
  +        }
  +    }
  +
  +    /* Utility Methods*/
  +    protected File fileFromKey(final Object key) {
  +        return IOUtils.createFile(this.directoryFile, key.toString());
  +    }
  +
  +    public String getString(final Object key)
  +    throws IOException {
  +        final File file = (File) this.get(key);
  +        if (file != null) {
  +            return IOUtils.deserializeString(file);
  +        }
  +
  +        return null;
  +    }
  +
  +    public void free() {}
  +
  +    public Object getObject(final Object key)
  +    throws IOException, ClassNotFoundException
  +    {
  +        final File file = (File) this.get(key);
  +        if (file != null) {
  +            return IOUtils.deserializeObject(file);
  +        }
  +
  +        return null;
  +    }
   }
  
  
  
  1.1.2.3   +5 -5      xml-cocoon2/src/org/apache/cocoon/components/store/StoreJanitor.java
  
  Index: StoreJanitor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/StoreJanitor.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- StoreJanitor.java	2001/09/07 11:13:53	1.1.2.2
  +++ StoreJanitor.java	2001/11/22 10:20:51	1.1.2.3
  @@ -16,11 +16,11 @@
    */
   public interface StoreJanitor extends Component {
   
  -  String ROLE = "org.apache.cocoon.components.store.StoreJanitor";
  +    String ROLE = "org.apache.cocoon.components.store.StoreJanitor";
   
  -  /** register method for the stores */
  -  void register(Store store);
  +    /** register method for the stores */
  +    void register(Store store);
   
  -  /** unregister method for the stores */
  -  void unregister(Store store);
  +    /** unregister method for the stores */
  +    void unregister(Store store);
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org