ozone core API

org.ozoneDB.core.storage.gammaStore
Class FileStorageFactory

java.lang.Object
  extended byorg.ozoneDB.core.storage.gammaStore.FileStorageFactory
All Implemented Interfaces:
PropertyConfigurable, StorageFactory
Direct Known Subclasses:
FileStreamStorageFactory, RandomAccessFileStorageFactory

public abstract class FileStorageFactory
extends java.lang.Object
implements StorageFactory, PropertyConfigurable

Abstract base class for storage factories that use files.

Version:
$Id: FileStorageFactory.java,v 1.3 2004/03/21 21:05:51 leomekenkamp Exp $
Author:
Leo Mekenkamp (mind the anti sp@m)

Field Summary
private  java.io.File directory
           
static PropertyInfo DIRECTORY
           
private static java.util.logging.Logger log
           
private static int NAMECONVERTRADIX
          Used to name directories.
private  java.lang.String prefix
           
private  int subdirectoryCount
           
static PropertyInfo SUBDIRECTORYCOUNT
           
private static java.lang.String SUBDIRECTORYCOUNT_KEY
           
private  int subdirectoryDepth
           
static PropertyInfo SUBDIRECTORYDEPTH
           
private static java.lang.String SUBDIRECTORYDEPTH_KEY
           
 
Constructor Summary
protected FileStorageFactory(java.util.Properties properties, java.lang.String prefix)
          As prescribed by the PropertyConfigurable interface.
 
Method Summary
 void delete(java.lang.String name)
          Deletes the data in the namespace of this instance specified by name.
 void deleteAll()
          Deletes all data that are in the namespace of this instance.
private  void deleteDirectory(java.io.File directory)
          deletes all files and subdirectories in the specified directory, but does _not_ delete the specified directory
protected  void ensureParentsExist(java.io.File file)
           
private  int findDepth(java.io.File directory, int startDepth)
           
protected  java.io.File getDirectory()
           
 java.lang.String getPrefix()
           
 java.util.Collection getPropertyInfos()
          Implementing classes should override this method, call super and add their own specific properties.
private  int getSubdirectoryCount()
           
private  int getSubdirectoryDepth()
           
private  void moveFiles(java.io.File directory, int relDepth, int targetDepth, int targetCount)
           
protected  java.io.File nameToFile(java.lang.String name)
           
protected  java.io.File nameToFile(java.lang.String name, int depth, int count)
          Returns the File that corresponds to the given name and depth.
private  void recursiveDeleteIfEmpty(java.io.File directory)
           
private  void setDirectory(java.io.File directory)
           
private  void setPrefix(java.lang.String prefix)
           
private  void setSubdirectoryCount(int subdirectoryCount)
           
private  void setSubdirectoryDepth(int depth)
          Sets the depth of subdirectories to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ozoneDB.core.storage.gammaStore.StorageFactory
createStorage
 

Field Detail

log

private static java.util.logging.Logger log

DIRECTORY

public static final PropertyInfo DIRECTORY

SUBDIRECTORYDEPTH_KEY

private static final java.lang.String SUBDIRECTORYDEPTH_KEY
See Also:
Constant Field Values

SUBDIRECTORYCOUNT_KEY

private static final java.lang.String SUBDIRECTORYCOUNT_KEY
See Also:
Constant Field Values

SUBDIRECTORYDEPTH

public static final PropertyInfo SUBDIRECTORYDEPTH

SUBDIRECTORYCOUNT

public static final PropertyInfo SUBDIRECTORYCOUNT

NAMECONVERTRADIX

private static final int NAMECONVERTRADIX

Used to name directories. We could take any value from 2 to Character.MAX_RADIX (36) here, but we settle for 16 because it looks nice and nerdy. 36 would look less nice because that could lead to directories with very nasty words in them when SUBDIRECTORYCOUNT is large enough.

See Also:
Constant Field Values

directory

private java.io.File directory

prefix

private java.lang.String prefix

subdirectoryDepth

private int subdirectoryDepth

subdirectoryCount

private int subdirectoryCount
Constructor Detail

FileStorageFactory

protected FileStorageFactory(java.util.Properties properties,
                             java.lang.String prefix)
As prescribed by the PropertyConfigurable interface.

Method Detail

findDepth

private int findDepth(java.io.File directory,
                      int startDepth)

delete

public void delete(java.lang.String name)
            throws java.io.IOException
Description copied from interface: StorageFactory

Deletes the data in the namespace of this instance specified by name. Typical file-based implementations would delete the file specified by name from the directory this instance uses.

Should not throw any exception if the specified file does not exist.

Specified by:
delete in interface StorageFactory
Parameters:
name - name of the data to delete
Throws:
java.io.IOException

deleteAll

public void deleteAll()
               throws java.io.IOException
Description copied from interface: StorageFactory

Deletes all data that are in the namespace of this instance. Typical file-based implementations would delete all files in the directory this instance uses.

Specified by:
deleteAll in interface StorageFactory
Returns:
true if data was deleted, false if otherwise.
Throws:
java.io.IOException

deleteDirectory

private void deleteDirectory(java.io.File directory)
                      throws java.io.IOException
deletes all files and subdirectories in the specified directory, but does _not_ delete the specified directory

Throws:
java.io.IOException

setSubdirectoryDepth

private void setSubdirectoryDepth(int depth)
                           throws java.io.IOException

Sets the depth of subdirectories to use. You must make sure that no reading or writing is taking place in the directory specified by getDirectory(), either by this class, or outside this class (for instance with 'cat' or 'type' in a shell / cmd window)

.

The whole directory structure is changed when this method is called, so it may take some time to complete.

Throws:
java.io.IOException

moveFiles

private void moveFiles(java.io.File directory,
                       int relDepth,
                       int targetDepth,
                       int targetCount)
                throws java.io.IOException
Throws:
java.io.IOException

recursiveDeleteIfEmpty

private void recursiveDeleteIfEmpty(java.io.File directory)
                             throws java.io.IOException
Throws:
java.io.IOException

getSubdirectoryDepth

private int getSubdirectoryDepth()

getPrefix

public java.lang.String getPrefix()
Specified by:
getPrefix in interface PropertyConfigurable

nameToFile

protected java.io.File nameToFile(java.lang.String name,
                                  int depth,
                                  int count)
Returns the File that corresponds to the given name and depth.


nameToFile

protected java.io.File nameToFile(java.lang.String name)

ensureParentsExist

protected void ensureParentsExist(java.io.File file)
                           throws java.io.IOException
Throws:
java.io.IOException

setPrefix

private void setPrefix(java.lang.String prefix)

getDirectory

protected java.io.File getDirectory()

setDirectory

private void setDirectory(java.io.File directory)

getPropertyInfos

public java.util.Collection getPropertyInfos()
Implementing classes should override this method, call super and add their own specific properties.

Specified by:
getPropertyInfos in interface PropertyConfigurable
Returns:
Collection with PropertyInfo elements

getSubdirectoryCount

private int getSubdirectoryCount()

setSubdirectoryCount

private void setSubdirectoryCount(int subdirectoryCount)

ozone core API

Copyright (C) The Ozone Database Project - www.ozone-db.org. All rights reserved.